diff --git a/pyproject.toml b/pyproject.toml index dae369525..626cd1f41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -162,8 +162,6 @@ ignore = [ "ARG002", # unused method argument "ARG003", # unused class method argument "ARG005", # unused lambda argument - # flake8-bugbear opinionated (disabled by default in flake8) - "B904", # within an except clause, raise exceptions with `raise ... from ...` # flake8-blind-except "BLE001", # do not catch blind exception # mccabe diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index a168e8d7f..a85f55014 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -6646,7 +6646,7 @@ class DefinitionParser(BaseParser): elif outer == 'function': desc = "If the function has no return type" else: - raise AssertionError + raise AssertionError from exUntyped prevErrors.append((exUntyped, desc)) self.pos = startPos try: @@ -6659,7 +6659,7 @@ class DefinitionParser(BaseParser): elif outer == 'function': desc = "If the function has a return type" else: - raise AssertionError + raise AssertionError from exUntyped prevErrors.append((exTyped, desc)) # Retain the else branch for easier debugging. # TODO: it would be nice to save the previous stacktrace @@ -6671,7 +6671,7 @@ class DefinitionParser(BaseParser): elif outer == 'function': header = "Error when parsing function declaration." else: - raise AssertionError + raise AssertionError from exUntyped raise self._make_multi_error(prevErrors, header) from exTyped else: # NoQA: RET506 # For testing purposes. @@ -6733,7 +6733,7 @@ class DefinitionParser(BaseParser): return ASTTemplateParamConstrainedTypeWithInit(type, typeInit) except DefinitionError as eType: if eExpr is None: - raise eType + raise errs = [] errs.append((eExpr, "If default template argument is an expression")) errs.append((eType, "If default template argument is a type")) @@ -6877,7 +6877,7 @@ class DefinitionParser(BaseParser): (eType, "If unconstrained type parameter or template type parameter")) errs.append( (eNonType, "If constrained type parameter or non-type parameter")) - raise self._make_multi_error(errs, header) + raise self._make_multi_error(errs, header) from None def _parse_template_parameter_list(self) -> ASTTemplateParams: # only: '<' parameter-list '>' diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 41da9df15..64450593e 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -286,7 +286,7 @@ class Autosummary(SphinxDirective): else: errors = exc.exceptions + [exc2] - raise ImportExceptionGroup(exc.args[0], errors) + raise ImportExceptionGroup(exc.args[0], errors) from None def create_documenter(self, app: Sphinx, obj: Any, parent: Any, full_name: str) -> Documenter: @@ -695,7 +695,7 @@ def _import_by_name(name: str, grouped_exception: bool = True) -> tuple[Any, Any except (ValueError, ImportError, AttributeError, KeyError) as exc: errors.append(exc) if grouped_exception: - raise ImportExceptionGroup('', errors) + raise ImportExceptionGroup('', errors) from None else: raise ImportError(*exc.args) from exc diff --git a/tests/test_build_epub.py b/tests/test_build_epub.py index 362ae4d6a..ba4741013 100644 --- a/tests/test_build_epub.py +++ b/tests/test_build_epub.py @@ -385,7 +385,7 @@ def test_run_epubcheck(app): except CalledProcessError as exc: print(exc.stdout.decode('utf-8')) print(exc.stderr.decode('utf-8')) - raise AssertionError('epubcheck exited with return code %s' % exc.returncode) + raise AssertionError(f'epubcheck exited with return code {exc.returncode}') from exc def test_xml_name_pattern_check(): diff --git a/tests/test_build_gettext.py b/tests/test_build_gettext.py index 44d6a55d5..6424f8dc0 100644 --- a/tests/test_build_gettext.py +++ b/tests/test_build_gettext.py @@ -74,7 +74,7 @@ def test_msgfmt(app): except CalledProcessError as exc: print(exc.stdout) print(exc.stderr) - raise AssertionError('msginit exited with return code %s' % exc.returncode) + raise AssertionError(f'msginit exited with return code {exc.returncode}') from exc assert (app.outdir / 'en_US.po').is_file(), 'msginit failed' try: @@ -86,7 +86,7 @@ def test_msgfmt(app): except CalledProcessError as exc: print(exc.stdout) print(exc.stderr) - raise AssertionError('msgfmt exited with return code %s' % exc.returncode) + raise AssertionError(f'msgfmt exited with return code {exc.returncode}') from exc mo = app.outdir / 'en' / 'LC_MESSAGES' / 'test_root.mo' assert mo.is_file(), 'msgfmt failed' diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 27088be08..38341c55d 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -73,7 +73,7 @@ def compile_latex_document(app, filename='python.tex', docclass='manual'): print(exc.stdout.decode('utf8')) print(exc.stderr.decode('utf8')) raise AssertionError(f'{app.config.latex_engine} exited with ' - f'return code {exc.returncode}') + f'return code {exc.returncode}') from exc def skip_if_requested(testfunc): diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index 7d851bbbe..97cc80c2b 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -56,7 +56,7 @@ def test_texinfo(app, status, warning): except CalledProcessError as exc: print(exc.stdout) print(exc.stderr) - raise AssertionError('makeinfo exited with return code %s' % exc.retcode) + raise AssertionError(f'makeinfo exited with return code {exc.retcode}') from exc @pytest.mark.sphinx('texinfo', testroot='markup-rubric') diff --git a/utils/babel_runner.py b/utils/babel_runner.py index cd228f4b1..dfb58db1f 100644 --- a/utils/babel_runner.py +++ b/utils/babel_runner.py @@ -231,7 +231,7 @@ if __name__ == '__main__': action = sys.argv[1].lower() except IndexError: print(__doc__, file=sys.stderr) - raise SystemExit(2) + raise SystemExit(2) from None os.chdir(ROOT) if action == "extract":