pytest/f606fef19d035719be6ed862f7f426a0e7c582e1.patch

45 lines
1.5 KiB
Diff

From 24898e06404fdade3c37c9229402ea817d068e75 Mon Sep 17 00:00:00 2001
From: Bruno Oliveira <nicoddemus@gmail.com>
Date: Sun, 5 Jan 2020 14:15:51 -0300
Subject: [PATCH] Remove usage of parser module, deprecated in Python 3.9
Fix #6404
---
changelog/6404.trivial.rst | 1 +
src/_pytest/_code/source.py | 9 ++-------
2 files changed, 3 insertions(+), 7 deletions(-)
create mode 100644 changelog/6404.trivial.rst
diff --git a/changelog/6404.trivial.rst b/changelog/6404.trivial.rst
new file mode 100644
index 0000000000..8252098b6a
--- /dev/null
+++ b/changelog/6404.trivial.rst
@@ -0,0 +1 @@
+Remove usage of ``parser`` module, deprecated in Python 3.9.
diff --git a/src/_pytest/_code/source.py b/src/_pytest/_code/source.py
index c8a4b6adf3..b35e97b9ce 100644
--- a/src/_pytest/_code/source.py
+++ b/src/_pytest/_code/source.py
@@ -123,18 +123,13 @@ def isparseable(self, deindent=True):
""" return True if source is parseable, heuristically
deindenting it by default.
"""
- from parser import suite as syntax_checker
-
if deindent:
source = str(self.deindent())
else:
source = str(self)
try:
- # compile(source+'\n', "x", "exec")
- syntax_checker(source + "\n")
- except KeyboardInterrupt:
- raise
- except Exception:
+ ast.parse(source)
+ except (SyntaxError, ValueError, TypeError):
return False
else:
return True