diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-01-16 21:40:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-16 21:40:34 +0900 |
commit | 90ab89311ff6f7f0074e6859f14805dc0ff0a082 (patch) | |
tree | 89b8183e147573e47d65645c9af1b2e788f63a93 /sphinx/pycode/ast.py | |
parent | d635d94eebbca0ebb1a5402aa07ed58c0464c6d3 (diff) | |
parent | eaa86125676729612ac0a1258161544cc5ebeb7a (diff) | |
download | sphinx-git-90ab89311ff6f7f0074e6859f14805dc0ff0a082.tar.gz |
Merge pull request #8667 from tk0miya/8652_invalid_type_comments
Fix #8652: autodoc: variable comments are ignored if invalid type comments found
Diffstat (limited to 'sphinx/pycode/ast.py')
-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 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. |