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 gvanrossum
Recipients Austin Bingham, christian.heimes, gvanrossum, mark.dickinson, rhettinger, robert_smallshire, serhiy.storchaka, tim.peters
Date 2020-10-04.19:16:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601838965.92.0.774534057581.issue26680@roundup.psfhosted.org>
In-reply-to
Content
Possibly at some point in the future we can switch to using typing.Protocol, which requires neither registration nor explicit subclassing (it's like Hashable). This makes it easy for user code to define custom protocols as needed. So if you need something that has .keys() and .items() but you don't care about .values() you can just write

class KeysAndItems(typing.Protocol):
    def keys(self): ...
    def items(self): ...

def my_func(x: KeysAndItems):
    ...

This can be statically checked using e.g. mypy.
History
Date User Action Args
2020-10-04 19:16:05gvanrossumsetrecipients: + gvanrossum, tim.peters, rhettinger, mark.dickinson, christian.heimes, serhiy.storchaka, robert_smallshire, Austin Bingham
2020-10-04 19:16:05gvanrossumsetmessageid: <1601838965.92.0.774534057581.issue26680@roundup.psfhosted.org>
2020-10-04 19:16:05gvanrossumlinkissue26680 messages
2020-10-04 19:16:05gvanrossumcreate