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 duplicate calls to __set_name__
for non-private attributes in BaseModel.__new__
#4410
Conversation
please review |
Ok, good catch. I'm afk, but I'll review this and revert the other pr when I'm back. |
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.
otherwise LGTM.
please update.
changes/4410-tlambert03.md
Outdated
@@ -0,0 +1 @@ | |||
Fix duplicate calls to `__set_name__` for non-private attributes in `BaseModel.__new__`. Add more tests. |
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.
This file can be removed, if anything, update the change from #4407.
You'll need to add "skip change file check" to the PR body.
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.
ok, all set this time for real 😂
sorry for the 2-step PR!
LGTM, @tlambert03 are you happy for this to be merged? (Just double checking 😆) |
🥴 yes! this time for realz |
Change Summary
My apologies @samuelcolvin, as I was working on adding the test you requested in #4407 (comment), I found a bug in my implementation, which is that
__set_name__
was now getting called twice for public attributes (i.e. anything innew_namespace
), and only once for private attributes. I didn't notice the auto-merge in time :)This PR fixes that, adds a test that
__set_name__
is called only once both for regularobject
subclasses as well asModelPrivateAttrs
, and adds the test requested above to make sure the bound method works (for regular objects... privateAttrs likely won't work for this pattern, as commented in the test)skip change file check
Related issue number
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)