Guido van Rossum <[email protected]> added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue26680>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com