Ivan Levkivskyi <levkivs...@gmail.com> added the comment:

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.

----------
nosy: +levkivskyi

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35190>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to