Jelle Zijlstra <[email protected]> added the comment:
I see the concerns about exposing too many implementation details.
But I'm also not sure how much this will really help static typing use cases.
Alex's examples just call super().keys(), but if you do that, there's not much
point in overriding keys() in the first place.
These classes don't allow subclassing or instantiation:
>>> t = type({}.items())
>>> class X(t):
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: type 'dict_items' is not an acceptable base type
>>> t({})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'dict_items' instances
So I can't think of much useful, well-typed code that you could write if these
classes were public. For a use case like SortedDict, you'd still need to write
your own class implementing KeysView, and you'd get an error from the type
checker because it's incompatible with dict_keys.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46399>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com