diff options
Diffstat (limited to 'Lib/abc.py')
-rw-r--r-- | Lib/abc.py | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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).""" |