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 grahamd
Recipients grahamd
Date 2021-08-06.06:56:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628233019.39.0.0281534175475.issue44847@roundup.psfhosted.org>
In-reply-to
Content
The Python standard library has two effective implementations of helpers for the ABCMeta class. A C implementation, and a pure Python version which is only used if the C implementation isn't available (perhaps for PyPy).

* https://github.com/python/cpython/blob/3.9/Lib/abc.py#L89
* https://github.com/python/cpython/blob/3.9/Lib/_py_abc.py
* https://github.com/python/cpython/blob/3.9/Modules/_abc.c

These two implementations behave differently.

Specifically, the ABCMeta.__subclasscheck__() implementation for the C version doesn't support duck typing for the subclass argument to issubclass() when this delegates to ABCMeta.__subclasscheck__(). The Python implementation for this has no problems though.

In the pure Python version it uses isinstance().

* https://github.com/python/cpython/blob/3.9/Lib/_py_abc.py#L110

In the C implementation it uses PyType_Check() which doesn't give the same result.

* https://github.com/python/cpython/blob/3.9/Modules/_abc.c#L610

The consequence of this is that transparent object proxies used as decorators on classes (eg., as wrapt uses) will break when the C implementation us used with an error of:

        #       def __subclasscheck__(cls, subclass):
        #           """Override for issubclass(subclass, cls)."""
        #   >       return _abc_subclasscheck(cls, subclass)
        #   E       TypeError: issubclass() arg 1 must be a class

Example of tests from wrapt and how tests using C implementation must be disabled can be found at:

* https://github.com/GrahamDumpleton/wrapt/blob/develop/tests/test_inheritance_py37.py

If instead of using PyType_Check() the C implementation used PyObject_IsInstance() at that point it is possible that wrapt may then work if the remainder of the C implementation is true to how the pure Python version works (not been able to test if that is the case or not as yet).
History
Date User Action Args
2021-08-06 06:56:59grahamdsetrecipients: + grahamd
2021-08-06 06:56:59grahamdsetmessageid: <1628233019.39.0.0281534175475.issue44847@roundup.psfhosted.org>
2021-08-06 06:56:59grahamdlinkissue44847 messages
2021-08-06 06:56:59grahamdcreate