Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-10 11:08:07 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-10 11:08:56 +0300
commiteaa86125676729612ac0a1258161544cc5ebeb7a (patch)
tree5f80cd4e3466b7eae28744211c278c02e4c24310 /sphinx/pycode
parent7acafa991b1da7f7ce1d8c179b0bba3ddf4feab6 (diff)
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.
Diffstat (limited to 'sphinx/pycode')
-rw-r--r--sphinx/pycode/ast.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/sphinx/pycode/ast.py b/sphinx/pycode/ast.py
index d131ff4c1..65534f958 100644
--- a/sphinx/pycode/ast.py
+++ b/sphinx/pycode/ast.py
@@ -52,6 +52,10 @@ def parse(code: str, mode: str = 'exec') -> "ast.AST":
try:
# type_comments parameter is available on py38+
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:
# fallback to ast module.
# typed_ast is used to parse type_comments if installed.