The Wayback Machine - https://web.archive.org/web/20221223110338/https://github.com/python/cpython/pull/100453
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-100407: [Docs] Improve __subclasshook__ example in abc.rst #100453

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Dec 23, 2022

There are several changes:

  1. __len__ is no longer there, because old-style iterable protocol does not need it, see
    return NULL;
  2. Foo is now fully runnable, so people can see what __getitem__ should look like
  3. any("__iter__" in B.__dict__ for B in C.__mro__) is simplified to be hasattr, much more common and much more pythonic (initial request by @JosephSBoyle)
  4. I've added a comment about why we need return NotImplemented here, see https://docs.python.org/3/library/abc.html#abc.ABCMeta.__subclasshook__
  5. self.__iter__() is much better as iter(self), calling magic methods directly is not something we should promote in this case. Now it is in sync with Foo.get_iterator()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants