[issue44606] Discrepancy between isinstance() and issubclass() for union types

Serhiy Storchaka report at bugs.python.org
Tue Jul 13 13:16:19 EDT 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

3. There is also a crash in isinstance():

>>> class BadMeta(type):
...     def __instancecheck__(cls, inst):
...         1/0
... 
>>> x = int | BadMeta('A', (), {})
>>> isinstance([], x)
Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set
Python runtime state: initialized
Traceback (most recent call last):
  File "<stdin>", line 3, in __instancecheck__
ZeroDivisionError: division by zero

The above exception was the direct cause of the following exception:

SystemError: <built-in method __instancecheck__ of types.Union object at 0x7f024bbb8960> returned a result with an exception set

Current thread 0x00007f024beb1280 (most recent call first):
  File "<stdin>", line 1 in <module>
Aborted (core dumped)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44606>
_______________________________________


More information about the Python-bugs-list mailing list