Title: isinstance() and issubclass() fail with abc.ABCMeta
Type: Severity: normal
Components: Core Versions: Jython 2.7
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, gthank, pjenvey, zyasoft
Priority: Keywords:

Created on 2013-05-20.09:52:20 by Arfrever, last changed 2014-05-13.20:08:48 by zyasoft.

msg8023 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2013-05-20.09:52:20
isinstance() and issubclass() fail with abc.ABCMeta in Jython. They work in CPython.

$ cat
import abc
class A(abc.ABCMeta): pass
print(isinstance(0, abc.ABCMeta))
print(issubclass(A, abc.ABCMeta))
print(issubclass(abc.ABCMeta, abc.ABCMeta))
$ python2.7
$ jython2.7
Traceback (most recent call last):
  File "", line 3, in <module>
    print(isinstance(0, abc.ABCMeta))
RuntimeError: maximum recursion depth exceeded in __instancecheck__
msg8024 (view) Author: Philip Jenvey (pjenvey) Date: 2013-05-20.18:08:27
It'd be helpful to know what method call inside of __instancecheck__ (I assume the message refers to ABCMeta.__instance__check__) ends up triggering the recursion
msg8397 (view) Author: Hank Gay (gthank) Date: 2014-05-13.19:49:42
Target beta 4.
msg8398 (view) Author: Jim Baker (zyasoft) Date: 2014-05-13.20:08:48
Interesting, I was reviewing and I see that there was a related problem in CPython earlier, as seen in the commented-out code. Of course this commented-out code actually works on both CPython and Jython now, so we have to fix Arfrever's case:

    def test_isinstance_class(self):
        class A:
            __metaclass__ = abc.ABCMeta
        class OldstyleClass:
        self.assertFalse(isinstance(OldstyleClass, A))
        self.assertTrue(isinstance(OldstyleClass, type(OldstyleClass)))
        self.assertFalse(isinstance(A, OldstyleClass))
        # This raises a recursion depth error, but is low-priority:
        # self.assertTrue(isinstance(A, abc.ABCMeta))
Date User Action Args
2014-05-13 20:08:48zyasoftsetnosy: + zyasoft
messages: + msg8398
2014-05-13 19:49:42gthanksetnosy: + gthank
messages: + msg8397
2014-05-04 20:29:36zyasoftsetresolution: accepted
2013-05-20 18:08:27pjenveysetmessages: + msg8024
2013-05-20 09:53:56Arfreversetnosy: + pjenvey
2013-05-20 09:52:20Arfrevercreate