diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-01-16 15:51:46 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-01-16 15:51:46 +0300 |
commit | 30f8640bab786b28e2fbc3a12a4cf212e6f953d1 (patch) | |
tree | f5cf23900a7bc509fe970262195995ddc526fda1 /sphinx/pycode | |
parent | 5460ea103bd91ce910e50e11e05c1e5340c2a9e0 (diff) | |
parent | 7c340e1c1c43f173f11efc14feb29cd08cedb995 (diff) |
Merge branch '3.x'
Diffstat (limited to 'sphinx/pycode')
-rw-r--r-- | sphinx/pycode/ast.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/sphinx/pycode/ast.py b/sphinx/pycode/ast.py index db9bfefb3..b9fbfc83d 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. |