[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers
Alex Waygood
report at bugs.python.org
Sun Jan 16 08:58:59 EST 2022
Alex Waygood <Alex.Waygood at Gmail.com> added the comment:
As a fix, I propose that two changes be made to `dict_keys`, `dict_values` and `dict_items`:
* They should be officially exposed in the `types` module.
* `__class_getitem__` should be added to the classes.
These two changes would mean that users would be able to do the following:
```
from types import dict_keys
from typing import TypeVar
K = TypeVar("K")
V = TypeVar("V")
class DictSubclass(dict[K, V]):
def keys(self) -> dict_keys[K, V]:
return super().keys()
```
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46399>
_______________________________________
More information about the Python-bugs-list
mailing list