|
7 | 7 | import sphinx |
8 | 8 | from sphinx.application import Sphinx |
9 | 9 | from sphinx.locale import __ |
10 | | -from sphinx.pycode.ast import parse as ast_parse |
11 | 10 | from sphinx.pycode.ast import unparse as ast_unparse |
12 | 11 | from sphinx.util import inspect, logging |
13 | 12 |
|
@@ -86,14 +85,14 @@ def get_type_comment(obj: Any, bound_method: bool = False) -> Signature: |
86 | 85 | if source.startswith((' ', r'\t')): |
87 | 86 | # subject is placed inside class or block. To read its docstring, |
88 | 87 | # this adds if-block before the declaration. |
89 | | - module = ast_parse('if True:\n' + source) |
| 88 | + module = ast.parse('if True:\n' + source, type_comments=True) |
90 | 89 | subject = cast(ast.FunctionDef, module.body[0].body[0]) # type: ignore |
91 | 90 | else: |
92 | | - module = ast_parse(source) |
93 | | - subject = cast(ast.FunctionDef, module.body[0]) # type: ignore |
| 91 | + module = ast.parse(source, type_comments=True) |
| 92 | + subject = cast(ast.FunctionDef, module.body[0]) |
94 | 93 |
|
95 | 94 | if getattr(subject, "type_comment", None): |
96 | | - function = ast_parse(subject.type_comment, mode='func_type') |
| 95 | + function = ast.parse(subject.type_comment, mode='func_type', type_comments=True) |
97 | 96 | return signature_from_ast(subject, bound_method, function) # type: ignore |
98 | 97 | else: |
99 | 98 | return None |
|
0 commit comments