gh-90104: avoid RecursionError on recursive dataclass field repr#100756
gh-90104: avoid RecursionError on recursive dataclass field repr#100756ericvsmith merged 4 commits intopython:mainfrom
Conversation
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.
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.
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.
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.
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.