From 48e2fbe94d16747ff19f87ff32cd45fbb9e01577 2013-01-17 18:42:02 From: MinRK Date: 2013-01-17 18:42:02 Subject: [PATCH] add istype to canning allows strict type checking, but accept tuples to check like isinstance. --- diff --git a/IPython/utils/pickleutil.py b/IPython/utils/pickleutil.py index 6547d58..428d451 100644 --- a/IPython/utils/pickleutil.py +++ b/IPython/utils/pickleutil.py @@ -208,6 +208,19 @@ def _import_mapping(mapping, original=None): else: mapping[cls] = mapping.pop(key) +def istype(obj, check): + """like isinstance(obj, check), but strict + + This won't catch subclasses. + """ + if isinstance(check, tuple): + for cls in check: + if type(obj) is cls: + return True + return False + else: + return type(obj) is check + def can(obj): """prepare an object for pickling""" @@ -217,7 +230,7 @@ def can(obj): if isinstance(cls, basestring): import_needed = True break - elif type(obj) is cls: + elif istype(obj, cls): return canner(obj) if import_needed: