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.

Author levkivskyi
Recipients docs@python, hroncok, levkivskyi, p-ganssle, rhettinger, serhiy.storchaka, stutzbach, vstinner
Date 2018-11-10.14:34:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541860492.79.0.788709270274.issue35190@psf.upfronthosting.co.za>
In-reply-to
Content
The separation may look arbitrary, but the idea is quite simple. Only those classes with few methods support structural checks. Those classes have few independent abstract methods (or even just one method), while in classes with large APIs like `Sequence`, the methods are not logically independent, so you can't say a class is 100% a `Sequence` even if types/signatures of all methods are correct, because e.g. `__contains__()` and `index()` should behave in agreement with `__getitem__()`.

We might explicitly document which ABCs support structural checks, and which require explicit subclassing. Also we might clarify what "abstract methods" and "mixin methods" mean in the table at the top. In the case of `Sequence` one can just implement two abstract methods and the other will behave in a "coordinated way". Then, simple purely abstract classes (called "One-trick ponies" in the source code) support structural checks.

> The collections.abc — Abstract Base Classes for Containers documentation says:

>> This module provides abstract base classes that can be used to test whether a class provides a particular interface; for example, whether it is hashable or whether it is a mapping.

Btw, Mapping also doesn't support structural checks, so the docs are quite outdated.
History
Date User Action Args
2018-11-10 14:34:52levkivskyisetrecipients: + levkivskyi, rhettinger, vstinner, stutzbach, docs@python, serhiy.storchaka, p-ganssle, hroncok
2018-11-10 14:34:52levkivskyisetmessageid: <1541860492.79.0.788709270274.issue35190@psf.upfronthosting.co.za>
2018-11-10 14:34:52levkivskyilinkissue35190 messages
2018-11-10 14:34:52levkivskyicreate