Bug report
Bug description:
For some reason calling Exception.__init__ breaks copy.copys ability to detect args. The following code
import copy
class MyException(Exception):
def __init__(self, x):
super().__init__()
self.x = x
my_exc = MyException(5)
copy.copy(my_exc)
gives
Traceback (most recent call last):
File "./foo.py", line 9, in <module>
copy.copy(my_exc)
File "/usr/lib/python3.12/copy.py", line 97, in copy
return _reconstruct(x, None, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/copy.py", line 253, in _reconstruct
y = func(*args)
^^^^^^^^^^^
TypeError: MyException.__init__() missing 1 required positional argument: 'x'
Removing the super().__init__() line makes everything work as expected, but given that it's generally seen as good practice to call super().__init__() in child classes, and you may be working with a more complex class structure, this seems like pretty bad behavior.
I haven't dug deep enough into copy.copy or BaseException.__init__ to decide which one deserves the blame.
For the reason why I want to copy exceptions, see python-trio/flake8-async#298
CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux
Bug report
Bug description:
For some reason calling
Exception.__init__breakscopy.copys ability to detectargs. The following codegives
Removing the
super().__init__()line makes everything work as expected, but given that it's generally seen as good practice to callsuper().__init__()in child classes, and you may be working with a more complex class structure, this seems like pretty bad behavior.I haven't dug deep enough into
copy.copyorBaseException.__init__to decide which one deserves the blame.For the reason why I want to copy exceptions, see python-trio/flake8-async#298
CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux