From c67f45b7166dd74c3cc8e52bf5fb86b2098456c7 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 9 Mar 2018 12:06:50 +0100 Subject: [PATCH] simplify a few imports in _pytest._code.source --- _pytest/_code/source.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/_pytest/_code/source.py b/_pytest/_code/source.py index 409961d9a..d7b86edbf 100644 --- a/_pytest/_code/source.py +++ b/_pytest/_code/source.py @@ -131,13 +131,7 @@ class Source(object): """ return True if source is parseable, heuristically deindenting it by default. """ - try: - import parser - except ImportError: - def syntax_checker(x): - return compile(x, 'asd', 'exec') - else: - syntax_checker = parser.suite + from parser import suite as syntax_checker if deindent: source = str(self.deindent()) @@ -219,9 +213,9 @@ def getfslineno(obj): """ Return source location (path, lineno) for the given object. If the source cannot be determined return ("", -1) """ - import _pytest._code + from .code import Code try: - code = _pytest._code.Code(obj) + code = Code(obj) except TypeError: try: fn = inspect.getsourcefile(obj) or inspect.getfile(obj) @@ -259,8 +253,8 @@ def findsource(obj): def getsource(obj, **kwargs): - import _pytest._code - obj = _pytest._code.getrawcode(obj) + from .code import getrawcode + obj = getrawcode(obj) try: strsrc = inspect.getsource(obj) except IndentationError: