Skip to content

Commit

Permalink
Fix flake8-bugbear warning
Browse files Browse the repository at this point in the history
B904 Within an `except` clause, raise exceptions with `raise ... from err`
     or `raise ... from None` to distinguish them from errors in exception
     handling
  • Loading branch information
DimitriPapadopoulos committed Jan 2, 2024
1 parent 3605641 commit 68a2356
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def _file_with_extension(directory, extension):
matching = (f for f in os.listdir(directory) if f.endswith(extension))
try:
(file,) = matching
except ValueError:
except ValueError as e:
raise ValueError(
'No distribution was found. Ensure that `setup.py` '
'is not empty and that it calls `setup()`.'
)
) from e
return file


Expand Down
4 changes: 2 additions & 2 deletions setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ def process_template_line(self, line):

try:
process_action = action_map[action]
except KeyError:
except KeyError as e:
raise DistutilsInternalError(
"this cannot happen: invalid action '{action!s}'".format(action=action),
)
) from e

# OK, now we know that the action is valid and we have the
# right number of words on the line for that action -- so we
Expand Down
8 changes: 4 additions & 4 deletions setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ def __setitem__(self, option_name, value):

try:
current_value = getattr(target_obj, option_name)
except AttributeError:
raise KeyError(option_name)
except AttributeError as e:
raise KeyError(option_name) from e

if current_value:
# Already inhabited. Skipping.
Expand Down Expand Up @@ -582,11 +582,11 @@ def _parse_version(self, value):
# accidentally include newlines and other unintended content
try:
Version(version)
except InvalidVersion:
except InvalidVersion as e:
raise OptionError(
f'Version loaded from {value} does not '
f'comply with PEP 440: {version}'
)
) from e

return version

Expand Down
4 changes: 2 additions & 2 deletions tools/build_launchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def get_msbuild():
]
try:
return subprocess.check_output(cmd, encoding='utf-8', text=True).strip()
except subprocess.CalledProcessError:
raise SystemExit("Unable to find MSBuild; check Visual Studio install")
except subprocess.CalledProcessError as e:
raise SystemExit("Unable to find MSBuild; check Visual Studio install") from e


def do_build(arena, platform, target):
Expand Down

0 comments on commit 68a2356

Please sign in to comment.