simplify a few imports in _pytest._code.source
This commit is contained in:
parent
d6ddeb395b
commit
c67f45b716
|
@ -131,13 +131,7 @@ class Source(object):
|
||||||
""" return True if source is parseable, heuristically
|
""" return True if source is parseable, heuristically
|
||||||
deindenting it by default.
|
deindenting it by default.
|
||||||
"""
|
"""
|
||||||
try:
|
from parser import suite as syntax_checker
|
||||||
import parser
|
|
||||||
except ImportError:
|
|
||||||
def syntax_checker(x):
|
|
||||||
return compile(x, 'asd', 'exec')
|
|
||||||
else:
|
|
||||||
syntax_checker = parser.suite
|
|
||||||
|
|
||||||
if deindent:
|
if deindent:
|
||||||
source = str(self.deindent())
|
source = str(self.deindent())
|
||||||
|
@ -219,9 +213,9 @@ def getfslineno(obj):
|
||||||
""" Return source location (path, lineno) for the given object.
|
""" Return source location (path, lineno) for the given object.
|
||||||
If the source cannot be determined return ("", -1)
|
If the source cannot be determined return ("", -1)
|
||||||
"""
|
"""
|
||||||
import _pytest._code
|
from .code import Code
|
||||||
try:
|
try:
|
||||||
code = _pytest._code.Code(obj)
|
code = Code(obj)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
try:
|
try:
|
||||||
fn = inspect.getsourcefile(obj) or inspect.getfile(obj)
|
fn = inspect.getsourcefile(obj) or inspect.getfile(obj)
|
||||||
|
@ -259,8 +253,8 @@ def findsource(obj):
|
||||||
|
|
||||||
|
|
||||||
def getsource(obj, **kwargs):
|
def getsource(obj, **kwargs):
|
||||||
import _pytest._code
|
from .code import getrawcode
|
||||||
obj = _pytest._code.getrawcode(obj)
|
obj = getrawcode(obj)
|
||||||
try:
|
try:
|
||||||
strsrc = inspect.getsource(obj)
|
strsrc = inspect.getsource(obj)
|
||||||
except IndentationError:
|
except IndentationError:
|
||||||
|
|
Loading…
Reference in New Issue