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.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/G32AS3U67GTCLGPV23G2NFKBFPU6WMLM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to