Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2b70bc

Browse files
committed
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.
1 parent d2dbecb commit e2b70bc

93 files changed

Lines changed: 215 additions & 313 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Include/abstract.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
11151115
/*
11161116
On success, return 1 if the mapping object has the key, key,
11171117
and 0 otherwise. This is equivalent to the Python expression:
1118-
o.has_key(key).
1118+
key in o.
11191119
11201120
This function always succeeds.
11211121
*/
@@ -1125,7 +1125,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
11251125
/*
11261126
Return 1 if the mapping object has the key, key,
11271127
and 0 otherwise. This is equivalent to the Python expression:
1128-
o.has_key(key).
1128+
key in o.
11291129
11301130
This function always succeeds.
11311131

Lib/DocXMLRPCServer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def generate_html_documentation(self):
174174
methods = {}
175175

176176
for method_name in self.system_listMethods():
177-
if self.funcs.has_key(method_name):
177+
if method_name in self.funcs:
178178
method = self.funcs[method_name]
179179
elif self.instance is not None:
180180
method_info = [None, None] # argspec, documentation

Lib/SimpleXMLRPCServer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def system_methodHelp(self, method_name):
313313
Returns a string containing documentation for the specified method."""
314314

315315
method = None
316-
if self.funcs.has_key(method_name):
316+
if method_name in self.funcs:
317317
method = self.funcs[method_name]
318318
elif self.instance is not None:
319319
# Instance can implement _methodHelp to return help for a method

Lib/UserDict.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def iteritems(self): return self.data.iteritems()
4141
def iterkeys(self): return self.data.iterkeys()
4242
def itervalues(self): return self.data.itervalues()
4343
def values(self): return self.data.values()
44-
def has_key(self, key): return self.data.has_key(key)
4544
def update(self, dict=None, **kwargs):
4645
if dict is None:
4746
pass
@@ -55,11 +54,11 @@ def update(self, dict=None, **kwargs):
5554
if len(kwargs):
5655
self.data.update(kwargs)
5756
def get(self, key, failobj=None):
58-
if not self.has_key(key):
57+
if key not in self:
5958
return failobj
6059
return self[key]
6160
def setdefault(self, key, failobj=None):
62-
if not self.has_key(key):
61+
if key not in self:
6362
self[key] = failobj
6463
return self[key]
6564
def pop(self, key, *args):
@@ -91,14 +90,12 @@ class DictMixin:
9190
def __iter__(self):
9291
for k in self.keys():
9392
yield k
94-
def has_key(self, key):
93+
def __contains__(self, key):
9594
try:
9695
value = self[key]
9796
except KeyError:
9897
return False
9998
return True
100-
def __contains__(self, key):
101-
return self.has_key(key)
10299

103100
# third level takes advantage of second level definitions
104101
def iteritems(self):

Lib/asyncore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def del_channel(self, map=None):
247247
fd = self._fileno
248248
if map is None:
249249
map = self._map
250-
if map.has_key(fd):
250+
if fd in map:
251251
#self.log_info('closing channel %d:%s' % (fd, self))
252252
del map[fd]
253253
self._fileno = None

Lib/bdb.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ def do_clear(self, arg):
133133
raise NotImplementedError, "subclass of bdb must implement do_clear()"
134134

135135
def break_anywhere(self, frame):
136-
return self.breaks.has_key(
137-
self.canonic(frame.f_code.co_filename))
136+
return self.canonic(frame.f_code.co_filename) in self.breaks
138137

139138
# Derived classes should override the user_* methods
140139
# to gain control.
@@ -245,7 +244,7 @@ def clear_break(self, filename, lineno):
245244
# pair, then remove the breaks entry
246245
for bp in Breakpoint.bplist[filename, lineno][:]:
247246
bp.deleteMe()
248-
if not Breakpoint.bplist.has_key((filename, lineno)):
247+
if (filename, lineno) not in Breakpoint.bplist:
249248
self.breaks[filename].remove(lineno)
250249
if not self.breaks[filename]:
251250
del self.breaks[filename]
@@ -453,7 +452,7 @@ def __init__(self, file, line, temporary=0, cond=None, funcname=None):
453452
Breakpoint.next = Breakpoint.next + 1
454453
# Build the two lists
455454
self.bpbynumber.append(self)
456-
if self.bplist.has_key((file, line)):
455+
if (file, line) in self.bplist:
457456
self.bplist[file, line].append(self)
458457
else:
459458
self.bplist[file, line] = [self]

Lib/bsddb/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ def has_key(self, key):
255255
self._checkOpen()
256256
return _DeadlockWrap(self.db.has_key, key)
257257

258+
__contains__ = has_key
259+
258260
def set_location(self, key):
259261
self._checkOpen()
260262
self._checkCursor()

Lib/bsddb/dbobj.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# added to _bsddb.c.
2222
#
2323

24-
import db
24+
from . import db
2525

2626
try:
2727
from UserDict import DictMixin
@@ -161,6 +161,8 @@ def key_range(self, *args, **kwargs):
161161
return self._cobj.key_range(*args, **kwargs)
162162
def has_key(self, *args, **kwargs):
163163
return self._cobj.has_key(*args, **kwargs)
164+
def __contains__(self, key):
165+
return self._cobj.has_key(key)
164166
def items(self, *args, **kwargs):
165167
return self._cobj.items(*args, **kwargs)
166168
def keys(self, *args, **kwargs):

Lib/bsddb/dbshelve.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
except ImportError:
3636
# DictMixin is new in Python 2.3
3737
class DictMixin: pass
38-
import db
38+
from . import db
3939

4040
#------------------------------------------------------------------------
4141

@@ -197,6 +197,10 @@ def join(self, cursorList, flags=0):
197197
raise NotImplementedError
198198

199199

200+
def __contains__(self, key):
201+
return self.has_key(key)
202+
203+
200204
#----------------------------------------------
201205
# Methods allowed to pass-through to self.db
202206
#

Lib/bsddb/dbutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def DeadlockWrap(function, *_args, **_kwargs):
5555
"""
5656
sleeptime = _deadlock_MinSleepTime
5757
max_retries = _kwargs.get('max_retries', -1)
58-
if _kwargs.has_key('max_retries'):
58+
if 'max_tries' in _kwargs:
5959
del _kwargs['max_retries']
6060
while True:
6161
try:

0 commit comments

Comments
 (0)