internal: clean up getfslineno#6656
Merged
blueyed merged 4 commits intopytest-dev:masterfrom Feb 4, 2020
Merged
Conversation
blueyed
commented
Feb 3, 2020
|
|
||
|
|
||
| def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int]: | ||
| def getfslineno(obj: Any) -> Tuple[Union[str, py.path.local], int]: |
Contributor
Author
There was a problem hiding this comment.
@bluetech had to take Any here instead of obj, for the place_as attribute check.
blueyed
commented
Feb 3, 2020
| return "", -1 | ||
|
|
||
| fspath = fn and py.path.local(fn) or None | ||
| fspath = fn and py.path.local(fn) or "" |
Contributor
Author
There was a problem hiding this comment.
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
approved these changes
Feb 4, 2020
Member
nicoddemus
left a comment
There was a problem hiding this comment.
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. 😁
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.