Commit cbcaae0
gh-145492: Fix defaultdict __repr__ infinite recursion
Move Py_ReprLeave(dd->default_factory) inside the else branch so it is
only called when Py_ReprEnter returned 0 (successfully entered). When
Py_ReprEnter detects recursion (returns > 0), it does not add a new
entry to the repr tracking list. Calling Py_ReprLeave in that case
incorrectly removed the entry from the outer (non-recursive) call,
which allowed subsequent recursive calls to bypass the guard entirely,
leading to infinite recursion.
Includes a regression test.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 0156133 commit cbcaae0
2 files changed
+18
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
207 | 222 | | |
208 | 223 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2385 | 2385 | | |
2386 | 2386 | | |
2387 | 2387 | | |
2388 | | - | |
| 2388 | + | |
2389 | 2389 | | |
2390 | | - | |
| 2390 | + | |
| 2391 | + | |
2391 | 2392 | | |
2392 | 2393 | | |
2393 | 2394 | | |
| |||
0 commit comments