cpython
3e245faf - gh-153772: Make abc isinstance() tolerate instances without __class__ (#154149)

Commit
4 days ago
gh-153772: Make abc isinstance() tolerate instances without __class__ (#154149) The built-in isinstance() reads an instance's __class__ with a lookup that suppresses AttributeError and falls back to the object's type, so isinstance(obj, int) returns False for an object whose __class__ access raises. ABCMeta.__instancecheck__ read __class__ directly instead, so isinstance(obj, Mapping) leaked that AttributeError. Fall back to type(instance) when __class__ is unavailable, in both the C and the pure-Python implementations, so the abstract base classes behave like the built-in isinstance(). Such objects are unusual, but they do turn up in the wild (for example some Qt widgets).
Author
Parents
Loading