Skip to content

Commit 3e6f0f3

Browse files
committed
Cleanup unhelpful alias _AST_FLAG
Also replace one direct call to `compile` with this flag with the equivalent wrapper `ast.parse`. This function can have a more precise type.
1 parent 4fb9cc3 commit 3e6f0f3

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/_pytest/_code/source.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import textwrap
66
import tokenize
77
import warnings
8-
from ast import PyCF_ONLY_AST as _AST_FLAG
98
from bisect import bisect_right
109
from types import FrameType
1110
from typing import Iterator
@@ -196,7 +195,7 @@ def compile(
196195
newex.text = ex.text
197196
raise newex
198197
else:
199-
if flag & _AST_FLAG:
198+
if flag & ast.PyCF_ONLY_AST:
200199
return co
201200
lines = [(x + "\n") for x in self.lines]
202201
# Type ignored because linecache.cache is private.
@@ -321,7 +320,7 @@ def getstatementrange_ast(
321320
# don't produce duplicate warnings when compiling source to find ast
322321
with warnings.catch_warnings():
323322
warnings.simplefilter("ignore")
324-
astnode = compile(content, "source", "exec", _AST_FLAG)
323+
astnode = ast.parse(content, "source", "exec")
325324

326325
start, end = get_statement_startend2(lineno, astnode)
327326
# we need to correct the end:

0 commit comments

Comments
 (0)