Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheriting from Exception breaks deepcopy on Python 2 #217

Closed
rouge8 opened this issue Jul 11, 2017 · 3 comments
Closed

Inheriting from Exception breaks deepcopy on Python 2 #217

rouge8 opened this issue Jul 11, 2017 · 3 comments

Comments

@rouge8
Copy link
Contributor

rouge8 commented Jul 11, 2017

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)
@rouge8
Copy link
Contributor Author

rouge8 commented Jul 11, 2017

Turns out this isn't attrs related, it's just Python 2 😩 :

>>> from copy import deepcopy
>>> class Foo(Exception):
...     def __init__(self, bar):
...         self.bar = bar
...
>>> 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)
>>>

@rouge8 rouge8 closed this as completed Jul 11, 2017
@hynek
Copy link
Member

hynek commented Jul 12, 2017

May I suggest Python 3.6? ;)

@rouge8
Copy link
Contributor Author

rouge8 commented Jul 12, 2017

I wish 😭 Migrating monoliths with poor test coverage will not be fun..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants