Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Conversation

ericvsmith
Copy link
Member

@ericvsmithericvsmith commentedSep 24, 2024
edited by github-actionsbot
Loading

blhsing reacted with thumbs up emoji
@ericvsmithericvsmith changed the titlegt-90562: Support zero argument super with dataclasses when slots=Truegh-90562: Support zero argument super with dataclasses when slots=TrueSep 24, 2024
@ericvsmithericvsmith self-assigned thisSep 24, 2024
Copy link
Member

@carljmcarljm left a 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?

B = dataclass(slots=True)(A)
self.assertIs(B().cls(), B)

# This is probably undesirable behavior, but is a function of
Copy link
Member

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" :)

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Heh. Will do.

Comment on lines 1304 to 1308
_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)
Copy link
Member

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?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good point. Will change.

Copy link
MemberAuthor

@ericvsmithericvsmith left a 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!

Comment on lines 1304 to 1308
_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)
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good point. Will change.

B = dataclass(slots=True)(A)
self.assertIs(B().cls(), B)

# This is probably undesirable behavior, but is a function of
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Heh. Will do.

ericvsmithand others added2 commitsSeptember 24, 2024 19:38
Apply review suggestions.Co-authored-by: Carl Meyer <carl@oddbird.net>
Copy link
Member

@carljmcarljm left a 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")

@ericvsmithericvsmith merged commit5c6e3b7 intopython:mainSep 25, 2024
36 checks passed
@ericvsmithericvsmith deleted the issue-90562-dataclasses-zero-argument-super branchSeptember 25, 2024 01:26
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@carljmcarljmcarljm approved these changes

Assignees

@ericvsmithericvsmith

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@ericvsmith@carljm

[8]ページ先頭

©2009-2025 Movatter.jp