mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix B904 (raise exceptions with `raise ... from ...`)
This commit is contained in:
@@ -162,8 +162,6 @@ ignore = [
|
|||||||
"ARG002", # unused method argument
|
"ARG002", # unused method argument
|
||||||
"ARG003", # unused class method argument
|
"ARG003", # unused class method argument
|
||||||
"ARG005", # unused lambda 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
|
# flake8-blind-except
|
||||||
"BLE001", # do not catch blind exception
|
"BLE001", # do not catch blind exception
|
||||||
# mccabe
|
# mccabe
|
||||||
|
|||||||
@@ -6646,7 +6646,7 @@ class DefinitionParser(BaseParser):
|
|||||||
elif outer == 'function':
|
elif outer == 'function':
|
||||||
desc = "If the function has no return type"
|
desc = "If the function has no return type"
|
||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError from exUntyped
|
||||||
prevErrors.append((exUntyped, desc))
|
prevErrors.append((exUntyped, desc))
|
||||||
self.pos = startPos
|
self.pos = startPos
|
||||||
try:
|
try:
|
||||||
@@ -6659,7 +6659,7 @@ class DefinitionParser(BaseParser):
|
|||||||
elif outer == 'function':
|
elif outer == 'function':
|
||||||
desc = "If the function has a return type"
|
desc = "If the function has a return type"
|
||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError from exUntyped
|
||||||
prevErrors.append((exTyped, desc))
|
prevErrors.append((exTyped, desc))
|
||||||
# Retain the else branch for easier debugging.
|
# Retain the else branch for easier debugging.
|
||||||
# TODO: it would be nice to save the previous stacktrace
|
# TODO: it would be nice to save the previous stacktrace
|
||||||
@@ -6671,7 +6671,7 @@ class DefinitionParser(BaseParser):
|
|||||||
elif outer == 'function':
|
elif outer == 'function':
|
||||||
header = "Error when parsing function declaration."
|
header = "Error when parsing function declaration."
|
||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError from exUntyped
|
||||||
raise self._make_multi_error(prevErrors, header) from exTyped
|
raise self._make_multi_error(prevErrors, header) from exTyped
|
||||||
else: # NoQA: RET506
|
else: # NoQA: RET506
|
||||||
# For testing purposes.
|
# For testing purposes.
|
||||||
@@ -6733,7 +6733,7 @@ class DefinitionParser(BaseParser):
|
|||||||
return ASTTemplateParamConstrainedTypeWithInit(type, typeInit)
|
return ASTTemplateParamConstrainedTypeWithInit(type, typeInit)
|
||||||
except DefinitionError as eType:
|
except DefinitionError as eType:
|
||||||
if eExpr is None:
|
if eExpr is None:
|
||||||
raise eType
|
raise
|
||||||
errs = []
|
errs = []
|
||||||
errs.append((eExpr, "If default template argument is an expression"))
|
errs.append((eExpr, "If default template argument is an expression"))
|
||||||
errs.append((eType, "If default template argument is a type"))
|
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"))
|
(eType, "If unconstrained type parameter or template type parameter"))
|
||||||
errs.append(
|
errs.append(
|
||||||
(eNonType, "If constrained type parameter or non-type parameter"))
|
(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:
|
def _parse_template_parameter_list(self) -> ASTTemplateParams:
|
||||||
# only: '<' parameter-list '>'
|
# only: '<' parameter-list '>'
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ class Autosummary(SphinxDirective):
|
|||||||
else:
|
else:
|
||||||
errors = exc.exceptions + [exc2]
|
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,
|
def create_documenter(self, app: Sphinx, obj: Any,
|
||||||
parent: Any, full_name: str) -> Documenter:
|
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:
|
except (ValueError, ImportError, AttributeError, KeyError) as exc:
|
||||||
errors.append(exc)
|
errors.append(exc)
|
||||||
if grouped_exception:
|
if grouped_exception:
|
||||||
raise ImportExceptionGroup('', errors)
|
raise ImportExceptionGroup('', errors) from None
|
||||||
else:
|
else:
|
||||||
raise ImportError(*exc.args) from exc
|
raise ImportError(*exc.args) from exc
|
||||||
|
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ def test_run_epubcheck(app):
|
|||||||
except CalledProcessError as exc:
|
except CalledProcessError as exc:
|
||||||
print(exc.stdout.decode('utf-8'))
|
print(exc.stdout.decode('utf-8'))
|
||||||
print(exc.stderr.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():
|
def test_xml_name_pattern_check():
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ def test_msgfmt(app):
|
|||||||
except CalledProcessError as exc:
|
except CalledProcessError as exc:
|
||||||
print(exc.stdout)
|
print(exc.stdout)
|
||||||
print(exc.stderr)
|
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'
|
assert (app.outdir / 'en_US.po').is_file(), 'msginit failed'
|
||||||
try:
|
try:
|
||||||
@@ -86,7 +86,7 @@ def test_msgfmt(app):
|
|||||||
except CalledProcessError as exc:
|
except CalledProcessError as exc:
|
||||||
print(exc.stdout)
|
print(exc.stdout)
|
||||||
print(exc.stderr)
|
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'
|
mo = app.outdir / 'en' / 'LC_MESSAGES' / 'test_root.mo'
|
||||||
assert mo.is_file(), 'msgfmt failed'
|
assert mo.is_file(), 'msgfmt failed'
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ def compile_latex_document(app, filename='python.tex', docclass='manual'):
|
|||||||
print(exc.stdout.decode('utf8'))
|
print(exc.stdout.decode('utf8'))
|
||||||
print(exc.stderr.decode('utf8'))
|
print(exc.stderr.decode('utf8'))
|
||||||
raise AssertionError(f'{app.config.latex_engine} exited with '
|
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):
|
def skip_if_requested(testfunc):
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ def test_texinfo(app, status, warning):
|
|||||||
except CalledProcessError as exc:
|
except CalledProcessError as exc:
|
||||||
print(exc.stdout)
|
print(exc.stdout)
|
||||||
print(exc.stderr)
|
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')
|
@pytest.mark.sphinx('texinfo', testroot='markup-rubric')
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ if __name__ == '__main__':
|
|||||||
action = sys.argv[1].lower()
|
action = sys.argv[1].lower()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print(__doc__, file=sys.stderr)
|
print(__doc__, file=sys.stderr)
|
||||||
raise SystemExit(2)
|
raise SystemExit(2) from None
|
||||||
|
|
||||||
os.chdir(ROOT)
|
os.chdir(ROOT)
|
||||||
if action == "extract":
|
if action == "extract":
|
||||||
|
|||||||
Reference in New Issue
Block a user