MCPcopy Index your code
hub / github.com/RustPython/RustPython / Mapping

Class Mapping

Lib/_collections_abc.py:775–824  ·  view source on GitHub ↗

A Mapping is a generic container for associating key/value pairs. This class provides concrete generic implementations of all methods except for __getitem__, __iter__, and __len__.

Source from the content-addressed store, hash-verified

773### MAPPINGS ###
774
775class Mapping(Collection):
776 """A Mapping is a generic container for associating key/value
777 pairs.
778
779 This class provides concrete generic implementations of all
780 methods except for __getitem__, __iter__, and __len__.
781 """
782
783 __slots__ = ()
784
785 # Tell ABCMeta.__new__ that this class should have TPFLAGS_MAPPING set.
786 __abc_tpflags__ = 1 << 6 # Py_TPFLAGS_MAPPING
787
788 @abstractmethod
789 def __getitem__(self, key):
790 raise KeyError
791
792 def get(self, key, default=None):
793 'D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.'
794 try:
795 return self[key]
796 except KeyError:
797 return default
798
799 def __contains__(self, key):
800 try:
801 self[key]
802 except KeyError:
803 return False
804 else:
805 return True
806
807 def keys(self):
808 "D.keys() -> a set-like object providing a view on D's keys"
809 return KeysView(self)
810
811 def items(self):
812 "D.items() -> a set-like object providing a view on D's items"
813 return ItemsView(self)
814
815 def values(self):
816 "D.values() -> an object providing a view on D's values"
817 return ValuesView(self)
818
819 def __eq__(self, other):
820 if not isinstance(other, Mapping):
821 return NotImplemented
822 return dict(self.items()) == dict(other.items())
823
824 __reversed__ = None
825
826Mapping.register(mappingproxy)
827Mapping.register(framelocalsproxy)

Callers 2

fromMethod · 0.50
py_newMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected