mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #8652: autodoc: variable comments are ignored if invalid type comments found
To avoid the crash of ModuleAnalyzer from invalid type comments, this start to retry parsing without type_comments=False when `ast.parse()` raises SyntaxError.
This commit is contained in:
parent
7acafa991b
commit
eaa8612567
2
CHANGES
2
CHANGES
@ -38,6 +38,8 @@ Bugs fixed
|
|||||||
* #8592: autodoc: ``:meta public:`` does not effect to variables
|
* #8592: autodoc: ``:meta public:`` does not effect to variables
|
||||||
* #8594: autodoc: empty __all__ attribute is ignored
|
* #8594: autodoc: empty __all__ attribute is ignored
|
||||||
* #8315: autodoc: Failed to resolve struct.Struct type annotation
|
* #8315: autodoc: Failed to resolve struct.Struct type annotation
|
||||||
|
* #8652: autodoc: All variable comments in the module are ignored if the module
|
||||||
|
contains invalid type comments
|
||||||
* #8306: autosummary: mocked modules are documented as empty page when using
|
* #8306: autosummary: mocked modules are documented as empty page when using
|
||||||
:recursive: option
|
:recursive: option
|
||||||
* #8618: html: kbd role produces incorrect HTML when compound-key separators (-,
|
* #8618: html: kbd role produces incorrect HTML when compound-key separators (-,
|
||||||
|
@ -52,6 +52,10 @@ def parse(code: str, mode: str = 'exec') -> "ast.AST":
|
|||||||
try:
|
try:
|
||||||
# type_comments parameter is available on py38+
|
# type_comments parameter is available on py38+
|
||||||
return ast.parse(code, mode=mode, type_comments=True) # type: ignore
|
return ast.parse(code, mode=mode, type_comments=True) # type: ignore
|
||||||
|
except SyntaxError:
|
||||||
|
# Some syntax error found. To ignore invalid type comments, retry parsing without
|
||||||
|
# type_comments parameter (refs: https://github.com/sphinx-doc/sphinx/issues/8652).
|
||||||
|
return ast.parse(code, mode=mode)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# fallback to ast module.
|
# fallback to ast module.
|
||||||
# typed_ast is used to parse type_comments if installed.
|
# typed_ast is used to parse type_comments if installed.
|
||||||
|
Loading…
Reference in New Issue
Block a user