From fc03481f36b90d3a9331aa081832c2eaabff3a5e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 5 Mar 2023 20:19:04 -0500 Subject: Use try/except in __setitem__. --- setuptools/config/setupcfg.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'setuptools') diff --git a/setuptools/config/setupcfg.py b/setuptools/config/setupcfg.py index 26ea37d8..d6e5f0bf 100644 --- a/setuptools/config/setupcfg.py +++ b/setuptools/config/setupcfg.py @@ -279,15 +279,14 @@ class ConfigHandler(Generic[Target]): ) def __setitem__(self, option_name, value): - unknown = tuple() target_obj = self.target_obj # Translate alias into real name. option_name = self.aliases.get(option_name, option_name) - current_value = getattr(target_obj, option_name, unknown) - - if current_value is unknown: + try: + current_value = getattr(target_obj, option_name) + except AttributeError: raise KeyError(option_name) if current_value: -- cgit v1.2.1