Author xitop
Recipients xitop
Date 2019-09-10.09:09:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568106581.16.0.558052842785.issue38085@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-09-10 09:09:41xitopsetrecipients: + xitop
2019-09-10 09:09:41xitopsetmessageid: <1568106581.16.0.558052842785.issue38085@roundup.psfhosted.org>
2019-09-10 09:09:41xitoplinkissue38085 messages
2019-09-10 09:09:40xitopcreate