This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JelleZijlstra
Recipients AlexWaygood, Dennis Sweeney, JelleZijlstra, gvanrossum, kj, kumaraditya, methane, rhettinger, serhiy.storchaka, sobolevn
Date 2022-01-19.15:38:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1642606725.15.0.0293351792014.issue46399@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-01-19 15:38:45JelleZijlstrasetrecipients: + JelleZijlstra, gvanrossum, rhettinger, methane, serhiy.storchaka, Dennis Sweeney, sobolevn, kj, kumaraditya, AlexWaygood
2022-01-19 15:38:45JelleZijlstrasetmessageid: <1642606725.15.0.0293351792014.issue46399@roundup.psfhosted.org>
2022-01-19 15:38:45JelleZijlstralinkissue46399 messages
2022-01-19 15:38:45JelleZijlstracreate