Repository navigation
Conversation
Hover on a stdlib method such as Path.read_text showed no docstring. Typeshed stubs declare many members inside `if sys.version_info` blocks, and the lookup that maps a stub declaration to its source declaration only searched the top level of a class body, so it gave up. Treat statements nested in `if` blocks as part of the enclosing scope when locating a declaration in the stub and in the source. Fixes meta#5568
|
✅ This PR meets all requirements from our pull request checklist. Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour. |
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D130437464. (Because this pull request was imported automatically, there will not be any future comments.) |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This branch has not been deployed
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.
Summary
Hover on Path(".").read_text() showed the signature but no docstring.
Typeshed stubs have no docstrings. Hover takes the docstring from the matching declaration in the runtime .py file instead. In pathlib.pyi, read_text
is declared under if sys.version_info >= (3, 13):. The lookup that maps a stub declaration to its source declaration (lsp_attributes.rs) only searched
the top level of a class body, so it never found the method.
This PR treats statements nested in if/elif/else blocks as part of the enclosing scope. It does this both when locating the declaration in the stub
and when searching the source.
Fixes #5568
Test Plan
docstring is found.
close the file."