summaryrefslogtreecommitdiff
path: root/sphinx/pycode
diff options
context:
space:
mode:
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>2022-04-19 00:10:02 +0100
committerAdam Turner <9087854+aa-turner@users.noreply.github.com>2022-10-17 15:22:06 +0100
commitb277abcb49d2c6d248518ea30a179cb52175d600 (patch)
tree59e64240d7e2e799728e0c8eeb93ae4509f396e3 /sphinx/pycode
parenteb6e137097ba7db3a4dd442855512b159bd2d4bb (diff)
downloadsphinx-git-b277abcb49d2c6d248518ea30a179cb52175d600.tar.gz
Use ``ast.parse`` from the standard library
Diffstat (limited to 'sphinx/pycode')
-rw-r--r--sphinx/pycode/ast.py7
-rw-r--r--sphinx/pycode/parser.py3
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