[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2021-12-23 Thread Carl Friedrich Bolz-Tereick


Carl Friedrich Bolz-Tereick  added the comment:

Or, in other words, in my opinion this is the root cause of the bug:

class Base:
def __init_subclass__(cls):
global broken_class
broken_class = cls
assert 0
try:
class Broken(Base): pass
except: pass
assert broken_class not in Base.__subclasses__()

The assert fails, which imo it shouldn't.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2021-12-23 Thread Carl Friedrich Bolz-Tereick


Carl Friedrich Bolz-Tereick  added the comment:

hm, I think I figured it out. The root cause is that even though the creation 
of the class Triffid fails, it can still be found via Animal.__subclasses__(), 
which the special subclass logic for ABCs is looking at. Triffid fills its 
_abc_impl data with some content, but Triffid._abc_impl was never successfully 
initialized, therefore it mutates the _abc_impl of its first base class Animal.

My conclusion would be that if a class is not successfully created, it 
shouldn't appear in the .__subclasses__() list of its bases.

See attached script for some illuminating prints.

--
nosy: +Carl.Friedrich.Bolz
Added file: https://bugs.python.org/file50515/x.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2021-12-15 Thread hongweipeng


Change by hongweipeng :


--
keywords: +patch
pull_requests: +28335
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30112

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2021-09-16 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Confirmed that this weird behavior is still present.  Am not sure when someone 
will have the time and inclination to drill into the cause.

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2021-09-16 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
nosy: +lukasz.langa

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2021-09-14 Thread xitop


xitop  added the comment:

2nd anniversary. Any reaction from developers would be appreciated. Thank you.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2020-12-25 Thread xitop


xitop  added the comment:

Python 3.9.1 is affected too.

--
versions: +Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2020-11-16 Thread hongweipeng


hongweipeng  added the comment:

Class `Triffid` failed to create in `__init_subclass__`, so 
`Triffid._abc_cache` uses its base class `_abc_cache`.

--
nosy: +hongweipeng

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2019-12-28 Thread xitop


xitop  added the comment:

Please, could some experienced Python developer take a look at this issue 
reported more than 3 month ago?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2019-10-21 Thread xitop


xitop  added the comment:

Same problem also in Python 3.6.8 and the new 3.8.0.

--
versions: +Python 3.6, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38085] Interrupting class creation in __init_subclass__ may lead to incorrect isinstance() and issubclass() results

2019-09-10 Thread xitop


New submission from xitop :

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

--
components: Interpreter Core
messages: 351599
nosy: xitop
priority: normal
severity: normal
status: open
title: Interrupting class creation in __init_subclass__ may lead to incorrect 
isinstance() and issubclass() results
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com