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

Class UserDict

Lib/collections/__init__.py:1172–1261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1170################################################################################
1171
1172class UserDict(_collections_abc.MutableMapping):
1173
1174 # Start by filling-out the abstract methods
1175 def __init__(self, dict=None, /, **kwargs):
1176 self.data = {}
1177 if dict is not None:
1178 self.update(dict)
1179 if kwargs:
1180 self.update(kwargs)
1181
1182 def __len__(self):
1183 return len(self.data)
1184
1185 def __getitem__(self, key):
1186 if key in self.data:
1187 return self.data[key]
1188 if hasattr(self.__class__, "__missing__"):
1189 return self.__class__.__missing__(self, key)
1190 raise KeyError(key)
1191
1192 def __setitem__(self, key, item):
1193 self.data[key] = item
1194
1195 def __delitem__(self, key):
1196 del self.data[key]
1197
1198 def __iter__(self):
1199 return iter(self.data)
1200
1201 # Modify __contains__ and get() to work like dict
1202 # does when __missing__ is present.
1203 def __contains__(self, key):
1204 return key in self.data
1205
1206 def get(self, key, default=None):
1207 if key in self:
1208 return self[key]
1209 return default
1210
1211
1212 # Now, add the methods in dicts but not in MutableMapping
1213 def __repr__(self):
1214 return repr(self.data)
1215
1216 def __or__(self, other):
1217 if isinstance(other, UserDict):
1218 return self.__class__(self.data | other.data)
1219 if isinstance(other, (dict, frozendict)):
1220 return self.__class__(self.data | other)
1221 return NotImplemented
1222
1223 def __ror__(self, other):
1224 if isinstance(other, UserDict):
1225 return self.__class__(other.data | self.data)
1226 if isinstance(other, (dict, frozendict)):
1227 return self.__class__(other | self.data)
1228 return NotImplemented
1229

Callers 13

test_dataMethod · 0.90
test_mixed_orMethod · 0.90
test_mixed_iorMethod · 0.90
test_dict_copyMethod · 0.90
test_constructorMethod · 0.90
test_simpleMethod · 0.90
test_custom_localsMethod · 0.90
test_run_stringflagsMethod · 0.90
test_run_fileexflagsMethod · 0.90

Calls

no outgoing calls

Tested by 12

test_dataMethod · 0.72
test_mixed_orMethod · 0.72
test_mixed_iorMethod · 0.72
test_dict_copyMethod · 0.72
test_constructorMethod · 0.72
test_simpleMethod · 0.72
test_custom_localsMethod · 0.72
test_run_stringflagsMethod · 0.72
test_run_fileexflagsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…