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.

classification
Title: Better docs for ABCMeta.__subclasshook__
Type: Stage:
Components: Documentation Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ncoghlan
Priority: normal Keywords:

Created on 2013-01-01 03:21 by ncoghlan, last changed 2022-04-11 14:57 by admin.

Messages (2)
msg178724 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-01-01 03:21
Authors of __subclasshook__ methods need to decide between returning True, False and NotImplemented in various cases. Making that decision requires a clear understanding that the checks in ABCMeta.__subclasscheck__ occur in the following order:

- explicit registrations
- the __subclasshook__ call
- ordinary inheritance

So, returning False from __subclasshook__ allows you to override normal rules of inheritance, while returning NotImplemented lets normal inheritance rules apply. Explicit registrations take precedence regardless.
msg178726 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-01-01 04:07
Also, we should probably explain the approach we chose to follow in the stdlib, where we block implicit inheritance of __subclasshook__ behaviour by include an explicit type check at the start of the implementation, so it always returns NotImplemented when the first argument is a subclass rather than the exact expected class.
History
Date User Action Args
2022-04-11 14:57:40adminsetgithub: 61035
2013-01-01 05:01:16Ramchandra Aptesetassignee: docs@python

components: + Documentation
nosy: + docs@python
2013-01-01 04:07:43ncoghlansetmessages: + msg178726
2013-01-01 03:21:37ncoghlancreate