Correctly resolve `collections(.abc)` class/method Definition to source file instead of typing.py or typeshed-fallback
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)
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!
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?
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.
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.
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.
@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' ?