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

Class MyMapping

Lib/test/test_pprint.py:705–719  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

703 def test_mapping_subclass_repr(self):
704 """Test that mapping ABC views use their ._mapping's __repr__."""
705 class MyMapping(Mapping):
706 def __init__(self, keys=None):
707 self._keys = {} if keys is None else dict.fromkeys(keys)
708
709 def __getitem__(self, item):
710 return self._keys[item]
711
712 def __len__(self):
713 return len(self._keys)
714
715 def __iter__(self):
716 return iter(self._keys)
717
718 def __repr__(self):
719 return f"{self.__class__.__name__}([{', '.join(map(repr, self._keys.keys()))}])"
720
721 m = MyMapping(["test", 1])
722 self.assertEqual(repr(m), "MyMapping(['test', 1])")

Callers 1

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…