Skip to content

Commit fcbb6f0

Browse files
committed
typing: fix getfslineno
Closes #6590.
1 parent 358b2ea commit fcbb6f0

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/_pytest/_code/source.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from bisect import bisect_right
99
from types import CodeType
1010
from types import FrameType
11+
from typing import Any
1112
from typing import Iterator
1213
from typing import List
1314
from typing import Optional
@@ -283,7 +284,7 @@ def compile_( # noqa: F811
283284
return s.compile(filename, mode, flags, _genframe=_genframe)
284285

285286

286-
def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int]:
287+
def getfslineno(obj: Any) -> Tuple[Union[str, py.path.local], int]:
287288
""" Return source location (path, lineno) for the given object.
288289
If the source cannot be determined return ("", -1).
289290
@@ -306,18 +307,16 @@ def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int
306307
except TypeError:
307308
return "", -1
308309

309-
fspath = fn and py.path.local(fn) or None
310+
fspath = fn and py.path.local(fn) or ""
310311
lineno = -1
311312
if fspath:
312313
try:
313314
_, lineno = findsource(obj)
314315
except IOError:
315316
pass
317+
return fspath, lineno
316318
else:
317-
fspath = code.path
318-
lineno = code.firstlineno
319-
assert isinstance(lineno, int)
320-
return fspath, lineno
319+
return code.path, code.firstlineno
321320

322321

323322
#

src/_pytest/compat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ def get_real_method(obj, holder):
308308

309309
def getfslineno(obj) -> Tuple[Union[str, py.path.local], int]:
310310
"""(**Deprecated**, use _pytest._code.source.getfslineno directly)"""
311-
from _pytest._code.source import getfslineno
311+
import _pytest._code.source
312312

313-
return getfslineno(obj)
313+
return _pytest._code.source.getfslineno(obj)
314314

315315

316316
def getimfunc(func):

0 commit comments

Comments
 (0)