microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 769 forks source link

Implement TypeDict's type hinting to dict subclass #6715

Open BerendKemper opened 4 days ago

BerendKemper commented 4 days ago

TypedDicts are awsome in combination with PyLance because thanks to PyLance i get to see type hinting from objects implementing a TypeDict. Such as in the screenshot the variable obj2 has Type Hinting.

Is there a feature out there that can implement a TypeDict's type hinting to a dict subclass (since, unlike TypeDict, a dict subclass can implement custom methods)?

Image

erictraut commented 4 days ago

TypedDict is how the Python type system supports dictionaries with individually-typed items. You can read more about this facility in the official Python typing spec. A regular dict subclass cannot specify the types of individual items, but you can use dict[str, Any] to represent a dictionary whose keys are all str and whose values are any type.