diff options
Diffstat (limited to 'sphinx/pycode')
| -rw-r--r-- | sphinx/pycode/ast.py | 7 | ||||
| -rw-r--r-- | sphinx/pycode/parser.py | 3 |
2 files changed, 8 insertions, 2 deletions
diff --git a/sphinx/pycode/ast.py b/sphinx/pycode/ast.py index e61b01d18..4997ab09e 100644 --- a/sphinx/pycode/ast.py +++ b/sphinx/pycode/ast.py @@ -1,8 +1,11 @@ """Helpers for AST (Abstract Syntax Tree).""" import ast +import warnings from typing import Dict, List, Optional, Type, overload +from sphinx.deprecation import RemovedInSphinx70Warning + OPERATORS: Dict[Type[ast.AST], str] = { ast.Add: "+", ast.And: "and", @@ -28,6 +31,10 @@ OPERATORS: Dict[Type[ast.AST], str] = { def parse(code: str, mode: str = 'exec') -> "ast.AST": """Parse the *code* using the built-in ast module.""" + warnings.warn( + "'sphinx.pycode.ast.parse' is deprecated, use 'ast.parse' instead.", + RemovedInSphinx70Warning, stacklevel=2 + ) try: return ast.parse(code, mode=mode, type_comments=True) except SyntaxError: diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index e537a7726..a51892e5e 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -11,7 +11,6 @@ from token import DEDENT, INDENT, NAME, NEWLINE, NUMBER, OP, STRING from tokenize import COMMENT, NL from typing import Any, Dict, List, Optional, Tuple -from sphinx.pycode.ast import parse as ast_parse from sphinx.pycode.ast import unparse as ast_unparse comment_re = re.compile('^\\s*#: ?(.*)\r?\n?$') @@ -552,7 +551,7 @@ class Parser: def parse_comments(self) -> None: """Parse the code and pick up comments.""" - tree = ast_parse(self.code) + tree = ast.parse(self.code, type_comments=True) picker = VariableCommentPicker(self.code.splitlines(True), self.encoding) picker.visit(tree) self.annotations = picker.annotations |
