diff --git a/changelog/6404.trivial.rst b/changelog/6404.trivial.rst new file mode 100644 index 000000000..8252098b6 --- /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 d7cef683d..2b9c2a6ea 100644 --- a/src/_pytest/_code/source.py +++ b/src/_pytest/_code/source.py @@ -140,18 +140,13 @@ class Source: """ 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