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.

classification
Title: Objects referencing private-mangled names do not roundtrip properly under pickling.
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Antony.Lee, ZackerySpytz, alexandre.vassalotti, josh.r, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-03-06 05:36 by Antony.Lee, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 21480 open ZackerySpytz, 2020-07-15 05:57
Messages (2)
msg313306 - (view) Author: Antony Lee (Antony.Lee) * Date: 2018-03-06 05:36
Consider the following example:

    import pickle

    class T:
        def __init__(self):
            self.attr = self.__foo

        def __foo(self):
            pass

    print(pickle.loads(pickle.dumps(T())))

This fails on 3.6 with `AttributeError: 'T' object has no attribute '__foo'` (i.e. there's a lookup on the unmangled name).  As a comparison, replacing `__foo` with `_foo` results in working code.
msg349838 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2019-08-16 00:36
This problem is specific to private methods AFAICT, since they're the only things which have an unmangled __name__ used to pickle them, but are stored as a mangled name.

More details on cause and solution on issue #37852, which I closed as a duplicate of this issue.
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77188
2020-07-15 17:51:11serhiy.storchakasetnosy: + serhiy.storchaka

versions: + Python 3.10, - Python 3.6, Python 3.7
2020-07-15 05:57:05ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request20623
stage: patch review
2019-08-16 00:36:40josh.rsetnosy: + josh.r

messages: + msg349838
versions: + Python 3.6, Python 3.8, Python 3.9
2019-08-16 00:34:52josh.rlinkissue37852 superseder
2018-03-09 20:21:18terry.reedysetnosy: + alexandre.vassalotti
2018-03-06 05:36:52Antony.Leecreate