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
Fix @frozen exceptions to allow __traceback__ to be set. #1081
Fix @frozen exceptions to allow __traceback__ to be set. #1081
Conversation
Ah nice I'm pretty sure I ran junk this myself when switching to 3.11 but decided to just thaw the class and get on with my life. Can you finish it up with a news fragment pls? |
6e3a7eb
to
a604fc2
Compare
Fixed! |
changelog.d/1081.change.rst
Outdated
@@ -0,0 +1 @@ | |||
Fix frozen exception classes when raised within e.g. `contextlib.contextmanager`, which mutates their ``__traceback__`` attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sir this is a Wendy's Markdown shop. 🤓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups, fix fixed then.
E.g. contextlib.contextmanager does so whenever an exception is raised in its body, and does so even on CPython, so merging the two code paths now seems reasonable.
a604fc2
to
388ecab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent thank you!
Summary
This code previously raised an
attrs.FrozenInstanceError
:on CPython (3.11 specifically, but probably other versions). On PyPy, it works, at least on 3.9 here -- which means I think it seems reasonable to merge the two codepaths here as I've done rather than whitelisting different attributes on different interpreters, but lemme know if you disagree.
(In real life a likely way you're going to encounter this, just to help anyone searching, is that
click
will wrap all exceptions during execution of a program, and does so via acontextlib.contextmanager
)Refs #712
Pull Request Check List
Our CI fails if coverage is not 100%.
.pyi
).tests/typing_example.py
.attr/__init__.pyi
, they've also been re-imported inattrs/__init__.pyi
.docs/api.rst
by hand.@attr.s()
have to be added by hand too.versionadded
,versionchanged
, ordeprecated
directives.Find the appropriate next version in our
__init__.py
file..rst
files is written using semantic newlines.changelog.d
.