Skip to content

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

@laundmo

Description

@laundmo

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)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions