mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
- Patch 1433928:
- The copy module now "copies" function objects (as atomic objects). - dict.__getitem__ now looks for a __missing__ hook before raising KeyError. - Added a new type, defaultdict, to the collections module. This uses the new __missing__ hook behavior added to dict (see above).
This commit is contained in:
parent
ab51f5f24d
commit
1968ad32cd
12 changed files with 611 additions and 10 deletions
|
@ -14,7 +14,12 @@ class UserDict:
|
|||
else:
|
||||
return cmp(self.data, dict)
|
||||
def __len__(self): return len(self.data)
|
||||
def __getitem__(self, key): return self.data[key]
|
||||
def __getitem__(self, key):
|
||||
if key in self.data:
|
||||
return self.data[key]
|
||||
if hasattr(self.__class__, "__missing__"):
|
||||
return self.__class__.__missing__(self, key)
|
||||
raise KeyError(key)
|
||||
def __setitem__(self, key, item): self.data[key] = item
|
||||
def __delitem__(self, key): del self.data[key]
|
||||
def clear(self): self.data.clear()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue