From b5a0ca12c09a86a24a03c0617c4398f3bbcb0b2d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 29 Jan 2020 22:07:43 +0100 Subject: [PATCH 1/2] typing: fix getfslineno (assignment) Fixes: > src/_pytest/_code/source.py:309: error: Incompatible types in > assignment (expression has type "Union[local, str]", variable has type > "Optional[local]") [assignment] --- src/_pytest/_code/source.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/_pytest/_code/source.py b/src/_pytest/_code/source.py index 379393b10cd..074d7c38f95 100644 --- a/src/_pytest/_code/source.py +++ b/src/_pytest/_code/source.py @@ -305,11 +305,9 @@ def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int _, lineno = findsource(obj) except IOError: pass + return fspath, lineno else: - fspath = code.path - lineno = code.firstlineno - assert isinstance(lineno, int) - return fspath, lineno + return code.path, code.firstlineno # From 67fd6a5dbbc5f6969813f604822b90d6029c3a60 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 29 Jan 2020 22:11:22 +0100 Subject: [PATCH 2/2] getfslineno: returns str Fixes: > src/_pytest/_code/source.py:310: error: Incompatible return value type > (got "Tuple[Union[local, str], int]", expected > "Tuple[Union[Literal[''], local, None], int]") [return-value] --- src/_pytest/_code/source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/_code/source.py b/src/_pytest/_code/source.py index 074d7c38f95..c40c872c7d5 100644 --- a/src/_pytest/_code/source.py +++ b/src/_pytest/_code/source.py @@ -282,7 +282,7 @@ def compile_( # noqa: F811 return s.compile(filename, mode, flags, _genframe=_genframe) -def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int]: +def getfslineno(obj) -> Tuple[Optional[Union[str, py.path.local]], int]: """ Return source location (path, lineno) for the given object. If the source cannot be determined return ("", -1).