-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-90104: avoid RecursionError on recursive dataclass field repr #100756
Conversation
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.
Thank you!
Lib/test/test_dataclasses.py
Outdated
rec_field.type = rec_field | ||
rec_field.name = "id" | ||
repr_output = repr(rec_field) | ||
expected_output = "Field(name='id',type=...," \ |
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 I'd just test that "type=..." is in the repr, not for the rest of the values. If new ones are added, this test would need to be modified.
Also, I think an additional test for the original problem:
@dataclass
class D:
C: C = field()
would be good.
Otherwise looks good!
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.
And to be clear: I'd just add the second test to make sure it doesn't raise RecursionError
, I wouldn't go nuts on testing the exact output.
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.
Let me know if the assertion in the new test qualifies as "going nuts" -- just seemed easy to check, and more confusing to have a test with no assertions at all.
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.
Maybe "go nuts" wasn't the best wording to use 😃. Your change is exactly what I would have done, down to the commas, so I think it's perfect. Thanks!
* main: pythonGH-100288: Remove LOAD_ATTR_METHOD_WITH_DICT instruction. (pythonGH-100753) pythonGH-100766: Note that locale.LC_MESSAGES is not universal (pythonGH-100702) Drop myself from pathlib maintenance (python#100757) pythongh-100739: Respect mock spec when checking for unsafe prefixes (python#100740)
Thanks @carljm for the PR, and @ericvsmith for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry, @carljm and @ericvsmith, I could not cleanly backport this to |
Sorry @carljm and @ericvsmith, I had trouble checking out the |
|
On the failing buildbot, |
I'll put up manual backport PRs since the auto-backporting failed. |
Thanks. I had started looking at doing this, but I'm having some issue with cherry_picker. I'm sure I'm doing something stupid.
Agreed. |
GH-100784 is a backport of this pull request to the 3.11 branch. |
…eld repr (pythongh-100756) Avoid RecursionError on recursive dataclass field repr (cherry picked from commit 0a7936a)
GH-100785 is a backport of this pull request to the 3.10 branch. |
Closes #90104.