Closed jakkdl closed 15 hours ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 99.58%. Comparing base (
2a66a0d
) to head (9aa6d36
). Report is 159 commits behind head on main.
🚨 Try these New Features:
This is a far better copy than most exception objects have, FYI. (I left a comment on the flake8-trio issue that motivated this.)
Thank you! I think we don't need to bother doing it either then, and I'll throw out the complicated logic.
it appears copy.copy
has bigger issues with exceptions than trio.Cancelled
, see https://github.com/python-trio/flake8-async/issues/298#issuecomment-2424971988
I'll probably close this PR
okay I think my original reasoning for this is no longer valid - copying is too unreliable to use in a general library like trio-websocket that needs to handle arbitrary user exceptions, but we should probably make it possible to copy & pickle Cancelled
for general usability reasons.
That's fairly straightforward by implementing __reduce__
, but it's maybe bad that all other NoPublicConstructor
classes remain unpickleable? I'm at least finding one somewhat related issue: https://github.com/python-trio/trio/issues/2135
See https://github.com/python-trio/flake8-async/issues/298 for why I want to be able to copy
Cancelled
.I suppose there's a minor footgun added if people start copying
Cancelled
,NoPublicConstructor
was added for a reason, but I think the gain outweighs it. Though of course another option is to simply get rid ofNoPublicConstructor
I initially tried to write cleaner methods, where I was using
__dict__
and the like, but they do not appear to pick up the relevant dunders so I simply listed everything relevant from https://docs.python.org/3/library/exceptions.html#exception-context