typing: PyobjMixin.reportinfo, getfslineno

This commit is contained in:
Daniel Hahler 2020-01-21 12:51:16 +01:00
parent 1350c601dc
commit 9c7b3c57d7
2 changed files with 7 additions and 5 deletions

View File

@ -307,7 +307,7 @@ def get_real_method(obj, holder):
return obj return obj
def getfslineno(obj): def getfslineno(obj) -> Tuple[Union[str, py.path.local], int]:
# xxx let decorators etc specify a sane ordering # xxx let decorators etc specify a sane ordering
obj = get_real_func(obj) obj = get_real_func(obj)
if hasattr(obj, "place_as"): if hasattr(obj, "place_as"):

View File

@ -12,6 +12,7 @@ from functools import partial
from textwrap import dedent from textwrap import dedent
from typing import List from typing import List
from typing import Tuple from typing import Tuple
from typing import Union
import py import py
@ -280,15 +281,16 @@ class PyobjMixin(PyobjContext):
parts.reverse() parts.reverse()
return ".".join(parts) return ".".join(parts)
def reportinfo(self) -> Tuple[str, int, str]: def reportinfo(self) -> Tuple[Union[py.path.local, str], int, str]:
# XXX caching? # XXX caching?
obj = self.obj obj = self.obj
compat_co_firstlineno = getattr(obj, "compat_co_firstlineno", None) compat_co_firstlineno = getattr(obj, "compat_co_firstlineno", None)
if isinstance(compat_co_firstlineno, int): if isinstance(compat_co_firstlineno, int):
# nose compatibility # nose compatibility
fspath = sys.modules[obj.__module__].__file__ file_path = sys.modules[obj.__module__].__file__
if fspath.endswith(".pyc"): if file_path.endswith(".pyc"):
fspath = fspath[:-1] file_path = file_path[:-1]
fspath = file_path # type: Union[py.path.local, str]
lineno = compat_co_firstlineno lineno = compat_co_firstlineno
else: else:
fspath, lineno = getfslineno(obj) fspath, lineno = getfslineno(obj)