Message416176
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') |
|
Date |
User |
Action |
Args |
2022-03-28 15:41:35 | vstinner | set | recipients:
+ vstinner, rhettinger, eric.smith, petr.viktorin, serhiy.storchaka, corona10 |
2022-03-28 15:41:35 | vstinner | set | messageid: <1648482095.68.0.170324316203.issue47143@roundup.psfhosted.org> |
2022-03-28 15:41:35 | vstinner | link | issue47143 messages |
2022-03-28 15:41:35 | vstinner | create | |
|