summaryrefslogtreecommitdiffstats
path: root/Lib/abc.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/abc.py')
-rw-r--r--Lib/abc.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/abc.py b/Lib/abc.py
index 8fb61c6..d86b6ea 100644
--- a/Lib/abc.py
+++ b/Lib/abc.py
@@ -162,8 +162,19 @@ class ABCMeta(type):
def __instancecheck__(cls, instance):
"""Override for isinstance(instance, cls)."""
- return any(cls.__subclasscheck__(c)
- for c in {instance.__class__, type(instance)})
+ # Inline the cache checking
+ subclass = instance.__class__
+ if subclass in cls._abc_cache:
+ return True
+ subtype = type(instance)
+ if subtype is subclass:
+ if (cls._abc_negative_cache_version ==
+ ABCMeta._abc_invalidation_counter and
+ subclass in cls._abc_negative_cache):
+ return False
+ # Fall back to the subclass check.
+ return cls.__subclasscheck__(subclass)
+ return any(cls.__subclasscheck__(c) for c in {subclass, subtype})
def __subclasscheck__(cls, subclass):
"""Override for issubclass(subclass, cls)."""