This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients corona10, eric.smith, petr.viktorin, rhettinger, serhiy.storchaka, vstinner
Date 2022-03-28.15:41:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1648482095.68.0.170324316203.issue47143@roundup.psfhosted.org>
In-reply-to
Content
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')
History
Date User Action Args
2022-03-28 15:41:35vstinnersetrecipients: + vstinner, rhettinger, eric.smith, petr.viktorin, serhiy.storchaka, corona10
2022-03-28 15:41:35vstinnersetmessageid: <1648482095.68.0.170324316203.issue47143@roundup.psfhosted.org>
2022-03-28 15:41:35vstinnerlinkissue47143 messages
2022-03-28 15:41:35vstinnercreate