Cheryl Sabella <cheryl.sabe...@gmail.com> added the comment:
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. ---------- nosy: +cheryl.sabella _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue23864> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com