[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

Akuli report at bugs.python.org
Fri Jan 21 03:55:19 EST 2022


Akuli <akuviljanen17 at gmail.com> added the comment:

I now agree that `# type: ignore` in dict subclasses makes sense the most, and exposing the views doesn't solve practical problems.

We talked more with the people who brought this up in typing. Turns out that the correct solution to their problems was to just inherit from MutableMapping instead of inheriting from dict. If you really need to inherit from dict and make .keys() do something else than it does by default, you're most likely trying to override all dict methods that do something with the keys, and you should just inherit from MutableMapping instead.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46399>
_______________________________________


More information about the Python-bugs-list mailing list