← 返回首页
gh-118033: Fix `__weakref__` not set for generic dataclasses by sobolevn · Pull Request #118099 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

gh-118033: Fix __weakref__ not set for generic dataclasses#118099

Merged
sobolevn merged 6 commits into
python:mainfrom
sobolevn:issue-118033
May 9, 2024
Merged

gh-118033: Fix __weakref__ not set for generic dataclasses#118099
sobolevn merged 6 commits into
python:mainfrom
sobolevn:issue-118033

Conversation

sobolevn commented Apr 19, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Looks like that classes with __weakrefoffset__ == 0 does not need to add __weakref__ slot to existing super ones.

sobolevn commented Apr 19, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

No, this is not correct, we also need to check __dictoffset__ as well. For __dict__ case.

Copy link
Copy Markdown
Member Author

Ubuntu failures are not related, there are some network problems right now

carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

I think this fix is correct; some suggestions and a question.

Comment thread Lib/dataclasses.py Outdated Show resolved Hide resolved
Comment thread Lib/dataclasses.py Outdated Show resolved Hide resolved
Comment thread Lib/dataclasses.py Outdated Show resolved Hide resolved
Comment thread Lib/dataclasses.py Show resolved Hide resolved
sobolevn requested a review from carljm May 4, 2024 09:05

carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

This looks fine to me. Sorry I didn't see the notification sooner that you requested another review!

I still think the best version of this might look at __weakrefoffset__ and __dictrefoffset__ always to decide on those two slots, but I agree that's an edge case and can be handled separately; this is still a clear improvement and fixes the original bug.

sobolevn added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels May 9, 2024
sobolevn enabled auto-merge (squash) May 9, 2024 08:09
sobolevn disabled auto-merge May 9, 2024 08:35
sobolevn enabled auto-merge (squash) May 9, 2024 08:35
sobolevn merged commit fa9b9cb into python:main May 9, 2024

Copy link
Copy Markdown

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 9, 2024
…ythonGH-118099) (cherry picked from commit fa9b9cb) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 9, 2024
…ythonGH-118099) (cherry picked from commit fa9b9cb) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

bedevere-app Bot commented May 9, 2024

Copy link
Copy Markdown

GH-118821 is a backport of this pull request to the 3.13 branch.

bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label May 9, 2024

bedevere-app Bot commented May 9, 2024

Copy link
Copy Markdown

GH-118822 is a backport of this pull request to the 3.12 branch.

bedevere-app Bot removed the needs backport to 3.12 only security fixes label May 9, 2024
sobolevn added a commit that referenced this pull request May 9, 2024
…H-118099) (#118821) gh-118033: Fix `__weakref__` not set for generic dataclasses (GH-118099) (cherry picked from commit fa9b9cb) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit that referenced this pull request May 9, 2024
…H-118099) (#118822) gh-118033: Fix `__weakref__` not set for generic dataclasses (GH-118099) (cherry picked from commit fa9b9cb) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Footer

© 2026 GitHub, Inc.