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

add __copy__ and __deep_copy__ to Cancelled #3105

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Oct 9, 2024

See python-trio/flake8-async#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 of NoPublicConstructor

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

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.58%. Comparing base (2a66a0d) to head (9aa6d36).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3105   +/-   ##
=======================================
  Coverage   99.58%   99.58%           
=======================================
  Files         121      121           
  Lines       18166    18191   +25     
  Branches     3275     3278    +3     
=======================================
+ Hits        18091    18116   +25     
  Misses         52       52           
  Partials       23       23           
Files with missing lines Coverage Δ
src/trio/_core/_exceptions.py 100.00% <100.00%> (ø)
src/trio/_core/_tests/test_run.py 100.00% <100.00%> (ø)

Copy link
Member

@CoolCat467 CoolCat467 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as far as I can tell

Copy link
Member

@oremanj oremanj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a far better copy than most exception objects have, FYI. (I left a comment on the flake8-trio issue that motivated this.)

src/trio/_core/_exceptions.py Outdated Show resolved Hide resolved
src/trio/_core/_exceptions.py Outdated Show resolved Hide resolved
@jakkdl
Copy link
Member Author

jakkdl commented Oct 9, 2024

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.

@jakkdl jakkdl requested a review from oremanj October 11, 2024 10:10
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

Successfully merging this pull request may close these issues.

3 participants