Skip to content
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

Correctly resolve collections(.abc) class/method Definition to source file instead of typing.py or typeshed-fallback #6316

Open
laundmo opened this issue Aug 28, 2024 · 6 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@laundmo
Copy link

laundmo commented Aug 28, 2024

Is your feature request related to a problem? Please describe.
Currently, Pyright resolves the Definition of types like collections.abc.MutableMapping as their alias assignment line in typing.py.

MutableMapping = _alias(collections.abc.MutableMapping, 2)

For methods like MutableMapping.pop it seems to resolve the Definition to typeshed-fallback instead, showing a list of overloads.

There are also currently no docstrings for collections.abc classes and their methods.

Describe the solution you’d like
As this is a relatively common and core part of type-hinting and part of stdlib, I'd really like custom behaviour here which can find the correct Definition in collections(.abc) which contains the actual implementation of these types or base classes.

This likely would require some custom behaviour for typing._SpecialGenericAlias which makes Pyright consider it more akin to a type alias.

Ideally, "Go to Definition" would show the actual source code of how something is implemented.

"Go to Declaration" could then show the typing.py alias line, and only "Go to Type Definition" would end up in typeshed-fallback.

At the same time, this should allow docstrings for these types to be resolved properly.

(Note: This was observed in both the latest release Pylance in vscode or latest release Pyright in vscode with Python 3.12.5 on Windows, but has existed across multiple machines and combinations of versions, which is why i assume this is not a bug but just a missing feature)

@erictraut
Copy link
Contributor

The completion suggestion functionality in pyright is maintained by the pylance team.

Could someone from the pylance team please transfer this feature request to the pylance-release project and triage it as you see fit? Thanks!

@debonte debonte transferred this issue from microsoft/pyright Aug 28, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 28, 2024
@laundmo
Copy link
Author

laundmo commented Aug 28, 2024

I'm not sure this move was correct. I just tested with the "Pyright" extension (while Pylance is uninstalled) and it has the exact same issues.

This is also not about "completion suggestion" at all... its about the "Find Definitions to quickly go to the location of a symbol’s definition" and "Hover over symbols to provide type information and doc strings" features listed here https://microsoft.github.io/pyright/#/features?id=language-server-support

Unless the pyright language server should also have issues reported in pylance-release?

@laundmo
Copy link
Author

laundmo commented Aug 28, 2024

as for repro, not sure how to provide one...
its really just

from collections.abc import MutableMapping

MutableMapping.get

and then hover over .get to see the lack of docstrings. Or place the cursor on .get and "Go to Definition" etc.

@erictraut
Copy link
Contributor

Pyright is focused on type checking functionality. It offers some basic language server features, but these are maintained by the pylance team. In general, any bugs or feature requests related to language server features get moved to the pylance-release project, and any bugs or feature requests related to type checking features get moved to the pyright project.

@heejaechang
Copy link
Contributor

the issue is our code that finds matching py from pyi (sourcemapper) doesn't know how to handle this case. code structure for these types is different between py files and pyi files.

ex) py has MutableMapping defined in _collections_abc.py but pyi has it defined in typing.pyi

probably need to add special case to handle these cases.

@bschnurr
Copy link
Member

bschnurr commented Oct 3, 2024

@heejaechang i'm thinking maybe go to definition should resolve the alias and never go to 'MutableMapping = _alias(collections.abc.MutableMapping, 2)' line.

for instance go to def on np in 'np.array' goes to the numpy's 'init.py'

import numpy as np

arr = np.array([1, 2, 3])

a special case for '_alias' ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

4 participants