-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-115165: Fix Annotated for immutable types #115213
Conversation
The return value from an annotated callable can raise any exception from __setattr__ for the `__orig_class__` property.
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.
Thanks!
I think this is safe to backport to the bugfix versions (3.11 and 3.12).
Misc/NEWS.d/next/Library/2024-02-09-07-20-16.gh-issue-115165.yfJLXA.rst
Outdated
Show resolved
Hide resolved
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.
Thanks! This is really great for a first contribution :)
A few small points below:
Misc/NEWS.d/next/Library/2024-02-09-07-20-16.gh-issue-115165.yfJLXA.rst
Outdated
Show resolved
Hide resolved
Update news blurb for pythongh-115165
Add comment justifying `except Exception`
Renamed test_annotated_callable_returning_immutable to test_instantiate_immutable and moved it near the other instantiation tests.
Add a test for generic instantiation that trips the same __setattr__ exception in Annotation.
@AlexWaygood and @JelleZijlstra -- thanks for the suggestions. I've addressed them locally. Do you prefer "fixup! ..." commits for auto-squashing or independent commits that will be preserved? |
It doesn't really matter, we squash the commits on merge. The only thing we generally ask for is to avoid force-pushing to your branch; that makes review harder. |
All commits will be squash-merged into a single commit by GitHub when we merge your PR into the |
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.
Thanks!
Thanks @dave-shawley for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
…-115213) The return value from an annotated callable can raise any exception from __setattr__ for the `__orig_class__` property. (cherry picked from commit 5643856) Co-authored-by: dave-shawley <[email protected]>
GH-115227 is a backport of this pull request to the 3.12 branch. |
…-115213) The return value from an annotated callable can raise any exception from __setattr__ for the `__orig_class__` property. (cherry picked from commit 5643856) Co-authored-by: dave-shawley <[email protected]>
GH-115228 is a backport of this pull request to the 3.11 branch. |
…) (#115227) gh-115165: Fix `typing.Annotated` for immutable types (GH-115213) The return value from an annotated callable can raise any exception from __setattr__ for the `__orig_class__` property. (cherry picked from commit 5643856) Co-authored-by: dave-shawley <[email protected]>
…) (#115228) gh-115165: Fix `typing.Annotated` for immutable types (GH-115213) The return value from an annotated callable can raise any exception from __setattr__ for the `__orig_class__` property. (cherry picked from commit 5643856) Co-authored-by: dave-shawley <[email protected]>
…15213) The return value from an annotated callable can raise any exception from __setattr__ for the `__orig_class__` property.
@JelleZijlstra @AlexWaygood Can this be backported to older versions too? |
Looks like it was backported to 3.11 and 3.12. Older versions only receive security fixes now, which this isn't. |
This PR widens the list of ignored exceptions when setting the
__orig_class__
attribute on the return value from an annotated callable. OnlyAttributeError
was caught yet instances can raise anyException
from__setattr__
. After this PR, it will catch anyException
instead. This change was motivated by theuuid.UUID.__setattr__
implementation raisesTypeError
.