Skip to content

Inheriting from Exception breaks deepcopy on Python 2 #217

@rouge8

Description

@rouge8

attrs classes that inherit from Exception on Python 2 cannot be deep copied:

>>> from copy import deepcopy
>>> import attr
>>> @attr.s
... class Foo(Exception):
...     bar = attr.ib()
...
>>> deepcopy(Foo(1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 329, in _reconstruct
    y = callable(*args)
TypeError: __init__() takes exactly 2 arguments (1 given)

Python 2.7.13, attrs 16.3.0, 17.2.0,and 50107f6 .

This is not an issue on Python 3:

>>> from copy import deepcopy
>>> import attr
>>> @attr.s
... class Foo(Exception):
...     bar = attr.ib()
...
>>> deepcopy(Foo(1))
Foo(bar=1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions