Skip to content

Cannot copy a class with a metaclass other than type #55689

Closed

Description

@durban
mannequin
BPO 11480
Nosy @ncoghlan, @pitrou, @avassalotti, @merwok, @durban
Files
  • copy_metaclass.patch
  • copy_metaclass_2.patch: Updated patch
  • 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 = 'https://github.com/avassalotti'
    closed_at = <Date 2013-12-01.21:27:54.650>
    created_at = <Date 2011-03-13.09:04:19.450>
    labels = ['type-bug', 'library']
    title = 'Cannot copy a class with a metaclass other than type'
    updated_at = <Date 2013-12-01.21:27:54.648>
    user = 'https://github.com/durban'

    bugs.python.org fields:

    activity = <Date 2013-12-01.21:27:54.648>
    actor = 'alexandre.vassalotti'
    assignee = 'alexandre.vassalotti'
    closed = True
    closed_date = <Date 2013-12-01.21:27:54.650>
    closer = 'alexandre.vassalotti'
    components = ['Library (Lib)']
    creation = <Date 2011-03-13.09:04:19.450>
    creator = 'daniel.urban'
    dependencies = []
    files = ['21100', '25806']
    hgrepos = []
    issue_num = 11480
    keywords = ['patch', 'needs review']
    message_count = 8.0
    messages = ['130731', '131343', '162211', '182891', '182893', '182894', '204965', '204966']
    nosy_count = 8.0
    nosy_names = ['ncoghlan', 'pitrou', 'alexandre.vassalotti', 'stutzbach', 'eric.araujo', 'daniel.urban', 'nailor', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue11480'
    versions = ['Python 3.3', 'Python 3.4']

    Activity

    1. durban commented on Mar 13, 2011

      durbanmannequin
      MannequinAuthor

      copy.copy cannot copy a class which have a metaclass other than type:

      >>> import abc
      >>> import copy
      >>> 
      >>> class C(metaclass=abc.ABCMeta):
      ...     pass
      ... 
      >>> copy.copy(C)
      Traceback (most recent call last):
          ...
      TypeError: can't pickle int objects

      The reason seems to be, as described in msg8329 (bpo-494904) that the __reduce_ex__ function inherited from object will be called instead of the method bound to the class object (that's the reason of the strange error message). (See also bpo-7689.)

      The interesting thing is, that copy.deepcopy was already fixed in 4680ef4fe90a. I'm attaching a patch, that does basically the same for copy that was done with deepcopy (it also includes a test).

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Mar 13, 2011
    3. merwok commented on Mar 18, 2011

      @merwok
      Member

      Looks good to me.

    4. durban commented on Jun 3, 2012

      durbanmannequin
      MannequinAuthor

      I've updated the patch to the current version. I've also checked, that the tests still pass.

    5. nailor commented on Feb 24, 2013

      nailormannequin
      Mannequin

      Hi, to be able to include your patch, could you sign the contributor form, please: http://www.python.org/psf/contrib/ ?

    6. durban commented on Feb 24, 2013

      durbanmannequin
      MannequinAuthor

      I did, and I've been told that it has been added to the bug tracker: http://mail.python.org/pipermail/python-committers/2012-May/001987.html

    7. nailor commented on Feb 24, 2013

      nailormannequin
      Mannequin

      Oh, my bad. The * was not just showing next to your name. Maybe someone with more access rights can help?

    8. python-dev commented on Dec 1, 2013

      python-devmannequin
      Mannequin

      New changeset c6bb6f304f75 by Alexandre Vassalotti in branch '3.3':
      Issue bpo-11480: Fixed copy.copy to work with classes with custom metaclasses.
      http://hg.python.org/cpython/rev/c6bb6f304f75

      New changeset c4715c9f442f by Alexandre Vassalotti in branch 'default':
      Issue bpo-11480: Merge with 3.3.
      http://hg.python.org/cpython/rev/c4715c9f442f

    9. avassalotti commented on Dec 1, 2013

      @avassalotti
      Member

      Thank you for the patch!

    10. self-assigned this
      on Dec 1, 2013
    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions