summaryrefslogtreecommitdiff
path: root/Lib/abc.py
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2008-03-17 16:31:21 +0000
committerJeffrey Yasskin <jyasskin@gmail.com>2008-03-17 16:31:21 +0000
commitb9e15f7555ed6596fa0af15f457389827ecab8f6 (patch)
tree52c49b8205f1c41e65909ac66f5daf2536cd4899 /Lib/abc.py
parent1b4e45bab940d385386e9442de5f5fbc7983dd50 (diff)
downloadcpython-git-b9e15f7555ed6596fa0af15f457389827ecab8f6.tar.gz
Make isinstance(OldstyleClass, NewstyleClass) return False instead of raising
an exception. Issue reported by Joseph Armbruster.
Diffstat (limited to 'Lib/abc.py')
-rw-r--r--Lib/abc.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/abc.py b/Lib/abc.py
index 5da2590e4f..5e90bf5f1a 100644
--- a/Lib/abc.py
+++ b/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))