STINNER Victor <vstin...@python.org> added the comment:

pickle.dump(x) checks if x is a type since commit 
f048a8f6d79173cc1da1bf12c60ae06fea36762c (March 2002) of bpo-494904:

    Pickler.save(): Fix for SF bug #494904: Cannot pickle a class with a
    metaclass, reported by Dan Parisien.

+            if issubclass(t, TypeType):
+                self.save_global(object)
+                return

Followed by a minor fix: commit 85ee491b3af3e1c124522249a52443b4d8c34c88 of 
bpo-502085:

    Don't die when issubclass(t, TypeType) fails.


-            if issubclass(t, TypeType):
+            try:
+                issc = issubclass(t, TypeType)
+            except TypeError: # t is not a class
+                issc = 0

copy.deepcopy(x) returns x if it's a type since commit 
11ade1ddc053dcec884e2431b55fb1c1727c65d7 (June 2002) of bpo-560794.

    SF patch 560794 (Greg Chapman): deepcopy can't handle custom
    metaclasses.

         try:
-            copier = x.__deepcopy__
-        except AttributeError:
+            issc = issubclass(type(x), type)
+        except TypeError:
+            issc = 0
+        if issc:
+            y = _deepcopy_dispatch[type](x, memo)
+        else:
             (...)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue47143>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to