(self)
| 205 | self.assertEqual(count, 2) |
| 206 | |
| 207 | def test_repr_recursive_factory(self): |
| 208 | # gh-145492: defaultdict.__repr__ should not cause infinite recursion |
| 209 | # when the factory's __repr__ calls repr() on the defaultdict. |
| 210 | class ProblematicFactory: |
| 211 | def __call__(self): |
| 212 | return {} |
| 213 | def __repr__(self): |
| 214 | repr(dd) |
| 215 | return f"ProblematicFactory for {dd}" |
| 216 | |
| 217 | dd = defaultdict(ProblematicFactory()) |
| 218 | # Should not raise RecursionError |
| 219 | r = repr(dd) |
| 220 | self.assertIn("ProblematicFactory for", r) |
| 221 | |
| 222 | if __name__ == "__main__": |
| 223 | unittest.main() |
nothing calls this directly
no test coverage detected