diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2013-12-14 23:22:21 -0500 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2013-12-14 23:22:21 -0500 |
commit | e3bab61df62c0e799dad6d844ea637597691e9fb (patch) | |
tree | 14f07c47de34e3bb9e5aaf527244fa656d025ed7 | |
parent | 4053aa99100e2fdc1a342a472492f53138a66d6b (diff) | |
download | pies-e3bab61df62c0e799dad6d844ea637597691e9fb.tar.gz |
Smarter _instancecheck_ override
-rw-r--r-- | pies/_utils.py | 4 | ||||
-rw-r--r-- | pies/overrides.py | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/pies/_utils.py b/pies/_utils.py index 14e5c44..f8937ae 100644 --- a/pies/_utils.py +++ b/pies/_utils.py @@ -55,6 +55,10 @@ def unmodified_isinstance(*bases): """ class UnmodifiedIsInstance(type): def __instancecheck__(cls, instance): + if cls.__name__ in (str(base.__name__) for base in bases): + return isinstance(instance, bases) + return type.__instancecheck__(cls, instance) + return isinstance(instance, bases) return with_metaclass(UnmodifiedIsInstance, *bases) diff --git a/pies/overrides.py b/pies/overrides.py index 02ad52f..c25eb87 100644 --- a/pies/overrides.py +++ b/pies/overrides.py @@ -208,7 +208,9 @@ else: return type.__new__(cls, name, bases, dct) def __instancecheck__(cls, instance): - return isinstance(instance, native_object) + if cls.__name__ == "object": + return isinstance(instance, native_object) + return type.__instancecheck__(cls, instance) class object(with_metaclass(FixStr, object)): pass |