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

The pickle module doesn't copy a type but gets it from its module. The Python 
implementation is pickle._Pickler.save_type() which calls 
pickle._Pickler.save_global().

The cloudpickle module doesn't copy types neither: same behavior than pickle.

Example:
---
import pickle
import pickletools

class A:
    pass

data = pickle.dumps(A)
pickletools.dis(data)
---

Output:
---
    0: \x80 PROTO      4
    2: \x95 FRAME      18
   11: \x8c SHORT_BINUNICODE '__main__'
   21: \x94 MEMOIZE    (as 0)
   22: \x8c SHORT_BINUNICODE 'A'
   25: \x94 MEMOIZE    (as 1)
   26: \x93 STACK_GLOBAL
   27: \x94 MEMOIZE    (as 2)
   28: .    STOP
highest protocol among opcodes = 4
---

In short, it's implemented as:

    getattr(__import__('__main__'), 'A')

----------

_______________________________________
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