Skip to content

Commit 96df8a4

Browse files
committed
py3compat for class canning
1 parent a8252bd commit 96df8a4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

IPython/utils/pickleutil.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import copy
1919
import logging
2020
import sys
21-
from types import FunctionType, ClassType
21+
from types import FunctionType
2222

2323
try:
2424
import cPickle as pickle
@@ -38,6 +38,10 @@
3838

3939
if py3compat.PY3:
4040
buffer = memoryview
41+
class_type = type
42+
else:
43+
from types import ClassType
44+
class_type = (type, ClassType)
4145

4246
#-------------------------------------------------------------------------------
4347
# Classes
@@ -129,7 +133,7 @@ def __init__(self, cls):
129133
self.buffers = []
130134

131135
def _check_type(self, obj):
132-
assert isinstance(obj, (type, ClassType)), "Not a class type"
136+
assert isinstance(obj, class_type), "Not a class type"
133137

134138
def get_object(self, g=None):
135139
parents = tuple(uncan(p, g) for p in self.parents)
@@ -225,7 +229,7 @@ def can(obj):
225229
return obj
226230

227231
def can_class(obj):
228-
if isinstance(obj, (type, ClassType)) and obj.__module__ == '__main__':
232+
if isinstance(obj, class_type) and obj.__module__ == '__main__':
229233
return CannedClass(obj)
230234
else:
231235
return obj
@@ -296,8 +300,7 @@ def uncan_sequence(obj, g=None):
296300
FunctionType : CannedFunction,
297301
bytes : CannedBytes,
298302
buffer : CannedBuffer,
299-
type : can_class,
300-
ClassType : can_class,
303+
class_type : can_class,
301304
}
302305

303306
uncan_map = {

0 commit comments

Comments
 (0)