Skip to content

Commit f606fef

Browse files
authored
[4.6] Remove usage of parser module, deprecated in Python 3.9 (#6408)
[4.6] Remove usage of parser module, deprecated in Python 3.9
2 parents b39b867 + 24898e0 commit f606fef

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

changelog/6404.trivial.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove usage of ``parser`` module, deprecated in Python 3.9.

src/_pytest/_code/source.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,13 @@ def isparseable(self, deindent=True):
123123
""" return True if source is parseable, heuristically
124124
deindenting it by default.
125125
"""
126-
from parser import suite as syntax_checker
127-
128126
if deindent:
129127
source = str(self.deindent())
130128
else:
131129
source = str(self)
132130
try:
133-
# compile(source+'\n', "x", "exec")
134-
syntax_checker(source + "\n")
135-
except KeyboardInterrupt:
136-
raise
137-
except Exception:
131+
ast.parse(source)
132+
except (SyntaxError, ValueError, TypeError):
138133
return False
139134
else:
140135
return True

0 commit comments

Comments
 (0)