Remove usage of parser module, deprecated in Python 3.9

Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1787902
This commit is contained in:
Miro Hrončok 2020-02-10 15:15:07 +01:00
parent b97286b671
commit 71d2106fc3
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,44 @@
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

View File

@ -6,6 +6,9 @@ License: MIT
URL: https://pytest.org
Source0: %{pypi_source}
# Remove usage of parser module, deprecated in Python 3.9
Patch1: https://github.com/pytest-dev/pytest/commit/f606fef19d035719be6ed862f7f426a0e7c582e1.patch
# The test in this specfile use pytest-timeout
# When building pytest for the first time with new Python version
# that is not possible as it depends on pytest