Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-144191: Dataclasses single field ordering#144222
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
base:main
Are you sure you want to change the base?
Conversation
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
johnslavik 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.
Thanks! You can wait for the green light from Eric before going forward or add tests for this even now. I'd probably changetest_1_field_compare. And of course a news entry, too.
Lib/dataclasses.py Outdated
| iflen(flds)==1: | ||
| self_expr=f"self.{flds[0].name}" | ||
| other_expr=f"other.{flds[0].name}" | ||
| else: | ||
| self_expr=_tuple_str('self',flds) | ||
| other_expr=_tuple_str('other',flds) |
johnslavikJan 26, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
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.
This is how I'd approach it:
| iflen(flds)==1: | |
| self_expr=f"self.{flds[0].name}" | |
| other_expr=f"other.{flds[0].name}" | |
| else: | |
| self_expr=_tuple_str('self',flds) | |
| other_expr=_tuple_str('other',flds) | |
| matchflds: | |
| # Special-case single field comparisons. See GH-144191. | |
| case [single_fld]: | |
| self_expr=f'self.{single_fld.name}' | |
| other_expr=f'other.{single_fld.name}' | |
| case_: | |
| self_expr=_tuple_str('self',flds) | |
| other_expr=_tuple_str('other',flds) |
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! I’ve updated the logic using match/case. It’s more readable and makes the intent clearer.
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Uh oh!
There was an error while loading.Please reload this page.
Simplify single-field dataclass ordering comparisons
#144191