|
18 | 18 | import copy |
19 | 19 | import logging |
20 | 20 | import sys |
21 | | -from types import FunctionType, ClassType |
| 21 | +from types import FunctionType |
22 | 22 |
|
23 | 23 | try: |
24 | 24 | import cPickle as pickle |
|
38 | 38 |
|
39 | 39 | if py3compat.PY3: |
40 | 40 | buffer = memoryview |
| 41 | + class_type = type |
| 42 | +else: |
| 43 | + from types import ClassType |
| 44 | + class_type = (type, ClassType) |
41 | 45 |
|
42 | 46 | #------------------------------------------------------------------------------- |
43 | 47 | # Classes |
@@ -129,7 +133,7 @@ def __init__(self, cls): |
129 | 133 | self.buffers = [] |
130 | 134 |
|
131 | 135 | 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" |
133 | 137 |
|
134 | 138 | def get_object(self, g=None): |
135 | 139 | parents = tuple(uncan(p, g) for p in self.parents) |
@@ -225,7 +229,7 @@ def can(obj): |
225 | 229 | return obj |
226 | 230 |
|
227 | 231 | def can_class(obj): |
228 | | - if isinstance(obj, (type, ClassType)) and obj.__module__ == '__main__': |
| 232 | + if isinstance(obj, class_type) and obj.__module__ == '__main__': |
229 | 233 | return CannedClass(obj) |
230 | 234 | else: |
231 | 235 | return obj |
@@ -296,8 +300,7 @@ def uncan_sequence(obj, g=None): |
296 | 300 | FunctionType : CannedFunction, |
297 | 301 | bytes : CannedBytes, |
298 | 302 | buffer : CannedBuffer, |
299 | | - type : can_class, |
300 | | - ClassType : can_class, |
| 303 | + class_type : can_class, |
301 | 304 | } |
302 | 305 |
|
303 | 306 | uncan_map = { |
|
0 commit comments