Author izbyshev
Recipients izbyshev, jab, levkivskyi, methane, serhiy.storchaka
Date 2018-03-09.13:59:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1520603961.46.0.467229070634.issue33018@psf.upfronthosting.co.za>
In-reply-to
Content
Regarding status quo (expanding the examples of @inada.naoki and @jab):

>>> import typing
>>> import collections.abc as cabc
>>> issubclass(typing.Mapping, cabc.Mapping)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/izbyshev/workspace/cpython/Lib/abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
>>> from abc import ABC
>>> issubclass(typing.Mapping, ABC)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/izbyshev/workspace/cpython/Lib/abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
  File "/home/izbyshev/workspace/cpython/Lib/abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
  File "/home/izbyshev/workspace/cpython/Lib/contextlib.py", line 30, in __subclasshook__
    return _collections_abc._check_methods(C, "__enter__", "__exit__")
  File "/home/izbyshev/workspace/cpython/Lib/_collections_abc.py", line 73, in _check_methods
    mro = C.__mro__
  File "/home/izbyshev/workspace/cpython/Lib/typing.py", line 706, in __getattr__
    raise AttributeError(attr)
AttributeError: __mro__
>>> ABC.register(int)
<class 'int'>
>>> issubclass(typing.Mapping, ABC)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/izbyshev/workspace/cpython/Lib/abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
>>> typing.Mapping.__mro__ = ()
>>> issubclass(typing.Mapping, ABC)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/izbyshev/workspace/cpython/Lib/abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
>>> typing.Mapping.__bases__ = ()
>>> issubclass(typing.Mapping, ABC)
False

Can't say that I'm OK with it :) 

I'm for forbidding non-types in ABCMeta.__subclasscheck__, but if we are to add clean support for "class-likes" instead, I think that "class-like" objects should be clearly defined, for example, that they must have __mro__ and __bases__ (and probably support weakrefs unless we want to skip caching if they don't). ABCMeta.__subclasscheck__ is not standalone: it relies on issubclass() and __subclasshook__, and both of them have some expectations in practice.
History
Date User Action Args
2018-03-09 13:59:21izbyshevsetrecipients: + izbyshev, jab, methane, serhiy.storchaka, levkivskyi
2018-03-09 13:59:21izbyshevsetmessageid: <1520603961.46.0.467229070634.issue33018@psf.upfronthosting.co.za>
2018-03-09 13:59:21izbyshevlinkissue33018 messages
2018-03-09 13:59:21izbyshevcreate