-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-142214: Fix two regressions in dataclasses #142223
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
Conversation
|
I am kicking myself on the It looks like the sqlalchemy field issue is from replacing and subsequently attempting to restore annotations in order to add fields to a dataclass as there's no mechanism for doing so without annotations. The check to fix this is fine, I'm actually surprised I hadn't written this as a comprehension. Again, sorry for missing these possibilities. |
Co-authored-by: sobolevn <[email protected]>
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.
I just locally applied the changes in Lib/dataclasses.py and it fixed all the failing tests on github.com/pipefunc/pipefunc.
ericvsmith
left a comment
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.
A small nit, but otherwise looks good to me.
| # gh-142214: The annotation may be missing in unusual dynamic cases. | ||
| # If so, just skip it. | ||
| if k in cls_annotations: | ||
| new_annotations[k] = cls_annotations[k] |
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.
Don't in and [] both do a lookup? Maybe it would be better as:
if ann := cls_annotations.get(k):
new_annotations[k] = annThere 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.
I believe that None is a valid annotation here so this would miss None values?
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.
Correct. To save a lookup we could do a try-except KeyError instead. I don't have a preference but I can switch to that if you like.
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.
I think try/except makes sense as in most cases the key should be there. The key not being there should only be in cases where something has modified annotations and removed things after the class has been processed.
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.
Done
|
When you're done making the requested changes, leave the comment: |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @ericvsmith: please review the changes made to this pull request. |
ericvsmith
left a comment
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.
Looks good to me. Thanks!
|
Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
(cherry picked from commit 53ec7c8) Co-authored-by: Jelle Zijlstra <[email protected]>
|
GH-142277 is a backport of this pull request to the 3.14 branch. |
__init__no longer work in 3.14.1 due to #137711 #142214