mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Not all code has been fixed yet; this is just a checkpoint... The C API still has PyDict_HasKey() and _HasKeyString(); not sure if I want to change those just yet.
This commit is contained in:
parent
d2dbecb4ae
commit
e2b70bcf74
93 changed files with 215 additions and 313 deletions
|
@ -120,13 +120,10 @@ class Mailbox:
|
|||
"""Return a list of (key, message) tuples. Memory intensive."""
|
||||
return list(self.iteritems())
|
||||
|
||||
def has_key(self, key):
|
||||
def __contains__(self, key):
|
||||
"""Return True if the keyed message exists, False otherwise."""
|
||||
raise NotImplementedError('Method must be implemented by subclass')
|
||||
|
||||
def __contains__(self, key):
|
||||
return self.has_key(key)
|
||||
|
||||
def __len__(self):
|
||||
"""Return a count of messages in the mailbox."""
|
||||
raise NotImplementedError('Method must be implemented by subclass')
|
||||
|
@ -330,7 +327,7 @@ class Maildir(Mailbox):
|
|||
continue
|
||||
yield key
|
||||
|
||||
def has_key(self, key):
|
||||
def __contains__(self, key):
|
||||
"""Return True if the keyed message exists, False otherwise."""
|
||||
self._refresh()
|
||||
return key in self._toc
|
||||
|
@ -515,7 +512,7 @@ class _singlefileMailbox(Mailbox):
|
|||
for key in self._toc.keys():
|
||||
yield key
|
||||
|
||||
def has_key(self, key):
|
||||
def __contains__(self, key):
|
||||
"""Return True if the keyed message exists, False otherwise."""
|
||||
self._lookup()
|
||||
return key in self._toc
|
||||
|
@ -902,7 +899,7 @@ class MH(Mailbox):
|
|||
return iter(sorted(int(entry) for entry in os.listdir(self._path)
|
||||
if entry.isdigit()))
|
||||
|
||||
def has_key(self, key):
|
||||
def __contains__(self, key):
|
||||
"""Return True if the keyed message exists, False otherwise."""
|
||||
return os.path.exists(os.path.join(self._path, str(key)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue