MCPcopy Index your code
hub / github.com/python/cpython / test_repr_recursive_factory

Method test_repr_recursive_factory

Lib/test/test_defaultdict.py:207–220  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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
222if __name__ == "__main__":
223 unittest.main()

Callers

nothing calls this directly

Calls 3

defaultdictClass · 0.85
ProblematicFactoryClass · 0.85
assertInMethod · 0.80

Tested by

no test coverage detected