Skip to content

Commit 5a17b0e

Browse files
DimitriPapadopoulosabravalheri
authored andcommitted
Fix flake8-bugbear warning
B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
1 parent f572296 commit 5a17b0e

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

setuptools/build_meta.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ def _file_with_extension(directory, extension):
117117
matching = (f for f in os.listdir(directory) if f.endswith(extension))
118118
try:
119119
(file,) = matching
120-
except ValueError:
120+
except ValueError as e:
121121
raise ValueError(
122122
'No distribution was found. Ensure that `setup.py` '
123123
'is not empty and that it calls `setup()`.'
124-
)
124+
) from e
125125
return file
126126

127127

setuptools/command/egg_info.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,10 @@ def process_template_line(self, line):
384384

385385
try:
386386
process_action = action_map[action]
387-
except KeyError:
387+
except KeyError as e:
388388
raise DistutilsInternalError(
389389
"this cannot happen: invalid action '{action!s}'".format(action=action),
390-
)
390+
) from e
391391

392392
# OK, now we know that the action is valid and we have the
393393
# right number of words on the line for that action -- so we

setuptools/config/setupcfg.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ def __setitem__(self, option_name, value):
283283

284284
try:
285285
current_value = getattr(target_obj, option_name)
286-
except AttributeError:
287-
raise KeyError(option_name)
286+
except AttributeError as e:
287+
raise KeyError(option_name) from e
288288

289289
if current_value:
290290
# Already inhabited. Skipping.
@@ -582,11 +582,11 @@ def _parse_version(self, value):
582582
# accidentally include newlines and other unintended content
583583
try:
584584
Version(version)
585-
except InvalidVersion:
585+
except InvalidVersion as e:
586586
raise OptionError(
587587
f'Version loaded from {value} does not '
588588
f'comply with PEP 440: {version}'
589-
)
589+
) from e
590590

591591
return version
592592

tools/build_launchers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def get_msbuild():
118118
]
119119
try:
120120
return subprocess.check_output(cmd, encoding='utf-8', text=True).strip()
121-
except subprocess.CalledProcessError:
122-
raise SystemExit("Unable to find MSBuild; check Visual Studio install")
121+
except subprocess.CalledProcessError as e:
122+
raise SystemExit("Unable to find MSBuild; check Visual Studio install") from e
123123

124124

125125
def do_build(arena, platform, target):

0 commit comments

Comments
 (0)