Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-90562: Support zero argument super with dataclasses when slots=True#124455
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
gh-90562: Support zero argument super with dataclasses when slots=True#124455
Uh oh!
There was an error while loading.Please reload this page.
Conversation
… showing that the original class, if saved, will have in incorrect __class__ value.
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 for working on this!
There is the possible case where all methods of a class are decorated with opaque decorators that don't usefunctools.wraps
, and thus we have no route to find the cell to update, and thus this approach simply fails. Should this case be mentioned in the tests? In the docs? Would it be worth explicitly introducing a__classcell__
member on classes through which the cell can reliably be accessed, so as to avoid this problem?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
B = dataclass(slots=True)(A) | ||
self.assertIs(B().cls(), B) | ||
# This is probably undesirable behavior, but is a function of |
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 we can safely remove this "probably" :)
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.
Heh. Will do.
Lib/dataclasses.py Outdated
_update_func_cell_for__class__(member, cls, newcls) | ||
elif isinstance(member, property): | ||
_update_func_cell_for__class__(member.fget, cls, newcls) | ||
_update_func_cell_for__class__(member.fset, cls, newcls) | ||
_update_func_cell_for__class__(member.fdel, cls, newcls) |
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 technically we could break out of the loop as soon as we've successfully updated one cell, because all the closures for a given class will always share a single__class__
cell. This may improve performance noticeably for larger classes?
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.
Good point. Will change.
Uh oh!
There was an error while loading.Please reload this page.
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 for the review,@carljm!
Lib/dataclasses.py Outdated
_update_func_cell_for__class__(member, cls, newcls) | ||
elif isinstance(member, property): | ||
_update_func_cell_for__class__(member.fget, cls, newcls) | ||
_update_func_cell_for__class__(member.fset, cls, newcls) | ||
_update_func_cell_for__class__(member.fdel, cls, newcls) |
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.
Good point. Will change.
Uh oh!
There was an error while loading.Please reload this page.
B = dataclass(slots=True)(A) | ||
self.assertIs(B().cls(), B) | ||
# This is probably undesirable behavior, but is a function of |
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.
Heh. Will do.
Uh oh!
There was an error while loading.Please reload this page.
Apply review suggestions.Co-authored-by: Carl Meyer <carl@oddbird.net>
…loop; minor change to comments; fix a test.
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!
(Discussed in person that if people hit the "all methods use an opaque decorator" case, the answer is "fix the decorator to usefunctools.wraps
")
5c6e3b7
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
📚 Documentation preview 📚:https://cpython-previews--124455.org.readthedocs.build/