On Mon, Sep 30, 2019 at 10:08 AM Andrew Barnert via Python-ideas <python-ideas@python.org> wrote:
Also, what we’re checking for really is subtyping.
Is it? Subtyping in type theory satisfies some axioms, one of which is transitivity. The addition of the ABCs broke transitivity: >>> issubclass(list, object) True >>> issubclass(object, collections.abc.Hashable) True >>> issubclass(list, collections.abc.Hashable) False ABC membership is a subtype relationship in some sense, and ordinary Python subclassing is a subtype relationship in some sense, but they aren't quite the same sense, and merging them creates an odd hybrid system in which I'm no longer sure which subclass relationships should hold, let alone which do. For example: >>> class A(collections.abc.Hashable): ... __hash__ = None ... >>> issubclass(A, collections.abc.Hashable) True >>> hash(A()) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'A' I didn't know what the issubclass call would return before I keyed in the example, and I can't decide what it should return. In contrast, I have no trouble deciding that the equivalent test implemented as a predicate ought to return False, since instances of A are in fact not hashable. I don't know how predicates would work in type annotations. And the ship has sailed. But I do think there's something wrong with the ABCs.