Skip to content

Objects referencing private-mangled names do not roundtrip properly under pickling. #77188

Closed

Description

@anntzer
mannequin
BPO 33007
Nosy @avassalotti, @serhiy-storchaka, @anntzer, @MojoVampire, @ZackerySpytz
PRs
  • gh-77188: Add support for pickling private methods and nested classes #21480
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2018-03-06.05:36:52.125>
    labels = ['3.8', 'library', '3.9', '3.10']
    title = 'Objects referencing private-mangled names do not roundtrip properly under pickling.'
    updated_at = <Date 2020-07-15.17:51:11.385>
    user = 'https://github.com/anntzer'

    bugs.python.org fields:

    activity = <Date 2020-07-15.17:51:11.385>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2018-03-06.05:36:52.125>
    creator = 'Antony.Lee'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33007
    keywords = ['patch']
    message_count = 2.0
    messages = ['313306', '349838']
    nosy_count = 5.0
    nosy_names = ['alexandre.vassalotti', 'serhiy.storchaka', 'Antony.Lee', 'josh.r', 'ZackerySpytz']
    pr_nums = ['21480']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue33007'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    Linked PRs

    Activity

    1. anntzer commented on Mar 6, 2018

      anntzermannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Mar 6, 2018
    3. MojoVampire commented on Aug 16, 2019

      MojoVampiremannequin
      Mannequin

      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 bpo-37852, which I closed as a duplicate of this issue.

    4. transferred this issue fromon Apr 10, 2022
    5. joeyagreco commented on Jul 8, 2022

      @joeyagreco

      Having this same issue on Python 3.10. Any updates on this?

    6. nanjekyejoannah commented on Oct 7, 2022

      @nanjekyejoannah
      Contributor

      @joeyagreco We have a PR if the author fixes, I can merge after some verification.

    7. ZackerySpytz commented on Dec 11, 2022

      @ZackerySpytz
      Contributor

      @nanjekyejoannah I have fixed the PR's merge conflicts.

    8. 13 remaining items

    9. serhiy-storchaka commented on Jan 6, 2026

      @serhiy-storchaka
      Member

      Since this never worked before, I reclassify this as a new feature.

      #21480 only handles private bound methods. Staticmethods, classmethods and unbound methods are not supported.

    10. added 2 commits that reference this issue on Jan 21, 2026
    11. added 2 commits that reference this issue on Jan 21, 2026
    12. added 2 commits that reference this issue on Jan 21, 2026
    13. added a commit that references this issue on Feb 5, 2026
    14. added 2 commits that reference this issue on Feb 15, 2026
    15. added a commit that references this issue on Apr 25, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions