Message332496
This isn't meant as a comment from any previous posts. It's simply meant to correct a statement (based on new information in the past 2 years) from the original post.
Since this original report, some ABCs that are not "One Trick Ponies" have been added which implement __subclasshook__. `Collection` is one of those, so using the original example:
>>> from collections.abc import Sequence, Container, Sized, Collection
>>> class MySequence(object):
... def __contains__(self, item): pass
... def __len__(self): pass
... def __iter__(self): pass
... def __getitem__(self, index): pass
... def __len__(self): pass
... def __reversed__(self): pass
... def index(self, item): pass
... def count(self, item): pass
...
>>> issubclass(MySequence, Container)
True
>>> issubclass(MySequence, Sized)
True
>>> issubclass(MySequence, Sequence)
False
>>> issubclass(MySequence, Collection)
True
Collection is not a "One Trick Pony" because it is used for Sized, Iterable Containers.
Generator, Coroutine, and ASyncGenerator are also not "One Trick Ponies" (although they are defined under that section in _collections_abc.py).
Again, for reference, the definition of One Trick Pony from PEP3119 is:
These abstract classes represent single methods like __iter__ or __len__.
If only One Trick Ponies implemented __subclasshook__, then the original documentation issue:
> These ABCs allow us to ask classes or instances if they provide particular functionality, for example:
maybe could have been changed to:
> These ABCs allow us to ask classes or instances if they provide singular functionality, for example:
But, that's not really correct anymore. |
|
Date |
User |
Action |
Args |
2018-12-24 17:53:46 | cheryl.sabella | set | recipients:
+ cheryl.sabella, gvanrossum, mjpieters, joncle, docs@python, eryksun, ztane, saulshanabrook, maggyero |
2018-12-24 17:53:44 | cheryl.sabella | set | messageid: <1545674024.53.0.712150888896.issue23864@roundup.psfhosted.org> |
2018-12-24 17:53:44 | cheryl.sabella | link | issue23864 messages |
2018-12-24 17:53:44 | cheryl.sabella | create | |
|