mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
Make isinstance(OldstyleClass, NewstyleClass) return False instead of raising
an exception. Issue reported by Joseph Armbruster.
This commit is contained in:
parent
1b4e45bab9
commit
b9e15f7555
2 changed files with 16 additions and 5 deletions
10
Lib/abc.py
10
Lib/abc.py
|
@ -116,18 +116,18 @@ class ABCMeta(type):
|
|||
|
||||
def __instancecheck__(cls, instance):
|
||||
"""Override for isinstance(instance, cls)."""
|
||||
# Inline the cache checking for new-style classes.
|
||||
subclass = instance.__class__
|
||||
# Inline the cache checking when it's simple.
|
||||
subclass = getattr(instance, '__class__', None)
|
||||
if subclass in cls._abc_cache:
|
||||
return True
|
||||
subtype = type(instance)
|
||||
if subtype is subclass:
|
||||
if subtype is subclass or subclass is None:
|
||||
if (cls._abc_negative_cache_version ==
|
||||
ABCMeta._abc_invalidation_counter and
|
||||
subclass in cls._abc_negative_cache):
|
||||
subtype in cls._abc_negative_cache):
|
||||
return False
|
||||
# Fall back to the subclass check.
|
||||
return cls.__subclasscheck__(subclass)
|
||||
return cls.__subclasscheck__(subtype)
|
||||
return (cls.__subclasscheck__(subclass) or
|
||||
cls.__subclasscheck__(subtype))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue