Message351599
An exception in __init__subclass__ leads under certain circumstances to wrong isinstance() and issubclass() results. The exception probably leaves Python internal data in inconsistent state.
Here is a demonstration program from Stack Overflow:
--- begin --
from abc import ABCMeta
class Animal(metaclass=ABCMeta):
pass
class Plant(metaclass=ABCMeta):
def __init_subclass__(cls):
assert not issubclass(cls, Animal), "Plants cannot be Animals"
class Dog(Animal):
pass
try:
class Triffid(Animal, Plant):
pass
except Exception:
pass
print("Dog is Animal?", issubclass(Dog, Animal))
print("Dog is Plant?", issubclass(Dog, Plant))
--- end --
Result is:
Dog is Animal? True
Dog is Plant? True
Changing the order of the print statements will result in:
Dog is Plant? False
Dog is Animal? False
Another ill-behaving program and a partial analysis can be found at SO: https://stackoverflow.com/q/57848663/5378816 |
|
Date |
User |
Action |
Args |
2019-09-10 09:09:41 | xitop | set | recipients:
+ xitop |
2019-09-10 09:09:41 | xitop | set | messageid: <1568106581.16.0.558052842785.issue38085@roundup.psfhosted.org> |
2019-09-10 09:09:41 | xitop | link | issue38085 messages |
2019-09-10 09:09:40 | xitop | create | |
|