Skip to content

copy.deepcopy barfs when copying a class derived from dict #41420

Closed

Description

@winjer
mannequin
BPO 1099746
Superseder
  • bpo-1100562: deepcopying listlike and dictlike objects
  • 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 = <Date 2008-01-20.19:30:38.381>
    created_at = <Date 2005-01-10.21:28:19.000>
    labels = ['library']
    title = 'copy.deepcopy barfs when copying a class derived from dict'
    updated_at = <Date 2008-01-20.19:30:38.380>
    user = 'https://bugs.python.org/winjer'

    bugs.python.org fields:

    activity = <Date 2008-01-20.19:30:38.380>
    actor = 'christian.heimes'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-01-20.19:30:38.381>
    closer = 'christian.heimes'
    components = ['Library (Lib)']
    creation = <Date 2005-01-10.21:28:19.000>
    creator = 'winjer'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 1099746
    keywords = []
    message_count = 2.0
    messages = ['60629', '60630']
    nosy_count = 2.0
    nosy_names = ['sonderblade', 'winjer']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '1100562'
    type = None
    url = 'https://bugs.python.org/issue1099746'
    versions = ['Python 2.3']

    Activity

    1. winjer commented on Jan 10, 2005

      winjermannequin
      MannequinAuthor

      I've got a class:

      class odict(dict):
      
         def __init__(self, d={}):
            self._keys = d.keys()
            dict.__init__(self, d)
      
         def __setitem__(self, key, item):
              dict.__setitem__(self, key, item)
              if key not in self._keys:
                  self._keys.append(key)

      ...

      When I copy.deepcopy one of these it blows up in
      __setitem__ with an AttributeError on _keys, because
      __setitem__ is called without __init__ ever having been
      called. Presumably this thing looks and smells like a
      dictionary, so deepcopy thinks it is one.

    2. added
      stdlib
      on Jan 10, 2005
    3. sonderblade commented on Jan 15, 2005

      sonderblademannequin
      Mannequin

      Logged In: YES
      user_id=51702

      See patch 1100562

    4. transferred this issue fromon Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlib

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions