-
-
Notifications
You must be signed in to change notification settings - Fork 3k
internal: clean up getfslineno #6656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
|
|
||
| def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int]: | ||
| def getfslineno(obj: Any) -> Tuple[Union[str, py.path.local], int]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bluetech had to take Any here instead of obj, for the place_as attribute check.
| return "", -1 | ||
|
|
||
| fspath = fn and py.path.local(fn) or None | ||
| fspath = fn and py.path.local(fn) or "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot really happen (becoming "", only if co_filename is empty on a code object, but that gets handled by Code then, which I've fixed to keep it (instead of turning it into cwd).
But I guess the or "" does not hurt - at least I'm confident that it never returned None actually.
Everything was using `_pytest.compat.getfslineno` basically, which wrapped `_pytest._code.source.getfslineno`. This moves the extra code from there into it directly, and uses the latter everywhere. This helps to eventually remove the one in compat eventually, and also causes less cyclic imports.
Previously this would be turned via `py.path.local("")` into the current
working directory.
This appears to be what `fspath = fn and py.path.local(fn) or None`
tries to avoid in `getfslineno`'s `TypeError` handling already, if
`Code` would raise it.
fcbb6f0 to
dab90ef
Compare
nicoddemus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup of getfslineno looks good to me, please consider just removing it from compat altogether now if possible.
The typing changes I did not review because I trust your judgement/knowledge in that area more than mine. 😁
Everything was using
_pytest.compat.getfslinenobasically, whichwrapped
_pytest._code.source.getfslineno.This moves the extra code from there into it directly, and uses the
latter everywhere.
This helps to eventually remove the one in compat eventually, and also
causes less cyclic imports.