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

Skip to content

Commit f1a69c1

Browse files
committed
Get rid of a bunch more has_key() uses. We *really* need a tool for this.
test_aepack now passes. IDLE still needs to be converted (among others).
1 parent 0da7e03 commit f1a69c1

16 files changed

Lines changed: 109 additions & 112 deletions

Lib/distutils/dir_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def remove_tree (directory, verbose=0, dry_run=0):
207207
cmd[0](cmd[1])
208208
# remove dir from cache if it's already there
209209
abspath = os.path.abspath(cmd[1])
210-
if _path_created.has_key(abspath):
210+
if abspath in _path_created:
211211
del _path_created[abspath]
212212
except (IOError, OSError), exc:
213213
log.warn(grok_environment_error(

Lib/distutils/msvccompiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def __init__ (self, verbose=0, dry_run=0, force=0):
239239

240240
def initialize(self):
241241
self.__paths = []
242-
if os.environ.has_key("DISTUTILS_USE_SDK") and os.environ.has_key("MSSdk") and self.find_exe("cl.exe"):
242+
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
243243
# Assume that the SDK set up everything alright; don't try to be
244244
# smarter
245245
self.cc = "cl.exe"

Lib/encodings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def search_function(encoding):
144144
pass
145145
else:
146146
for alias in codecaliases:
147-
if not _aliases.has_key(alias):
147+
if alias not in _aliases:
148148
_aliases[alias] = modname
149149

150150
# Return the registry entry

Lib/msilib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def add_file(self, file, src=None, version=None, language=None):
326326
file = os.path.basename(file)
327327
absolute = os.path.join(self.absolute, src)
328328
assert not re.search(r'[\?|><:/*]"', file) # restrictions on long names
329-
if self.keyfiles.has_key(file):
329+
if file in self.keyfiles:
330330
logical = self.keyfiles[file]
331331
else:
332332
logical = None

Lib/plat-mac/EasyDialogs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,17 +577,17 @@ def _process_Nav_args(dftflags, **args):
577577
if args[k] is None:
578578
del args[k]
579579
# Set some defaults, and modify some arguments
580-
if not args.has_key('dialogOptionFlags'):
580+
if 'dialogOptionFlags' not in args:
581581
args['dialogOptionFlags'] = dftflags
582-
if args.has_key('defaultLocation') and \
582+
if 'defaultLocation' in args and \
583583
not isinstance(args['defaultLocation'], Carbon.AE.AEDesc):
584584
defaultLocation = args['defaultLocation']
585585
if isinstance(defaultLocation, (Carbon.File.FSSpec, Carbon.File.FSRef)):
586586
args['defaultLocation'] = aepack.pack(defaultLocation)
587587
else:
588588
defaultLocation = Carbon.File.FSRef(defaultLocation)
589589
args['defaultLocation'] = aepack.pack(defaultLocation)
590-
if args.has_key('typeList') and not isinstance(args['typeList'], Carbon.Res.ResourceType):
590+
if 'typeList' in args and not isinstance(args['typeList'], Carbon.Res.ResourceType):
591591
typeList = args['typeList'][:]
592592
# Workaround for OSX typeless files:
593593
if 'TEXT' in typeList and not '\0\0\0\0' in typeList:
@@ -597,7 +597,7 @@ def _process_Nav_args(dftflags, **args):
597597
data = data+type
598598
args['typeList'] = Carbon.Res.Handle(data)
599599
tpwanted = str
600-
if args.has_key('wanted'):
600+
if 'wanted' in args:
601601
tpwanted = args['wanted']
602602
del args['wanted']
603603
return args, tpwanted

Lib/plat-mac/FrameWork.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def dispatch(self, event):
216216
if self.do_dialogevent(event):
217217
return
218218
(what, message, when, where, modifiers) = event
219-
if eventname.has_key(what):
219+
if what in eventname:
220220
name = "do_" + eventname[what]
221221
else:
222222
name = "do_%d" % what
@@ -247,7 +247,7 @@ def do_dialogevent(self, event):
247247
gotone, dlg, item = DialogSelect(event)
248248
if gotone:
249249
window = dlg.GetDialogWindow()
250-
if self._windows.has_key(window):
250+
if window in self._windows:
251251
self._windows[window].do_itemhit(item, event)
252252
else:
253253
print 'Dialog event for unknown dialog'
@@ -261,7 +261,7 @@ def do_mouseDown(self, event):
261261
#
262262
# Find the correct name.
263263
#
264-
if partname.has_key(partcode):
264+
if partcode in partname:
265265
name = "do_" + partname[partcode]
266266
else:
267267
name = "do_%d" % partcode
@@ -276,7 +276,7 @@ def do_mouseDown(self, event):
276276
if hasattr(MacOS, 'HandleEvent'):
277277
MacOS.HandleEvent(event)
278278
return
279-
elif self._windows.has_key(wid):
279+
elif wid in self._windows:
280280
# It is a window. Hand off to correct window.
281281
window = self._windows[wid]
282282
try:
@@ -363,7 +363,7 @@ def do_key(self, event):
363363
else:
364364
# See whether the front window wants it
365365
w = MyFrontWindow()
366-
if w and self._windows.has_key(w):
366+
if w and w in self._windows:
367367
window = self._windows[w]
368368
try:
369369
do_char = window.do_char
@@ -378,7 +378,7 @@ def do_char(self, c, event):
378378
def do_updateEvt(self, event):
379379
(what, message, when, where, modifiers) = event
380380
wid = WhichWindow(message)
381-
if wid and self._windows.has_key(wid):
381+
if wid and wid in self._windows:
382382
window = self._windows[wid]
383383
window.do_rawupdate(wid, event)
384384
else:
@@ -388,7 +388,7 @@ def do_updateEvt(self, event):
388388
def do_activateEvt(self, event):
389389
(what, message, when, where, modifiers) = event
390390
wid = WhichWindow(message)
391-
if wid and self._windows.has_key(wid):
391+
if wid and wid in self._windows:
392392
window = self._windows[wid]
393393
window.do_activate(modifiers & 1, event)
394394
else:
@@ -408,7 +408,7 @@ def do_osEvt(self, event):
408408
def do_suspendresume(self, event):
409409
(what, message, when, where, modifiers) = event
410410
wid = MyFrontWindow()
411-
if wid and self._windows.has_key(wid):
411+
if wid and wid in self._windows:
412412
window = self._windows[wid]
413413
window.do_activate(message & 1, event)
414414

@@ -432,7 +432,7 @@ def do_unknownevent(self, event):
432432
def printevent(self, event):
433433
(what, message, when, where, modifiers) = event
434434
nicewhat = repr(what)
435-
if eventname.has_key(what):
435+
if what in eventname:
436436
nicewhat = eventname[what]
437437
print nicewhat,
438438
if what == kHighLevelEvent:
@@ -512,7 +512,7 @@ def fixmenudimstate(self):
512512
label, shortcut, callback, kind = menu.items[i]
513513
if type(callback) == types.StringType:
514514
wid = MyFrontWindow()
515-
if wid and self.parent._windows.has_key(wid):
515+
if wid and wid in self.parent._windows:
516516
window = self.parent._windows[wid]
517517
if hasattr(window, "domenu_" + callback):
518518
menu.menu.EnableMenuItem(i + 1)
@@ -528,7 +528,7 @@ def fixmenudimstate(self):
528528
pass
529529

530530
def dispatch(self, id, item, window, event):
531-
if self.menus.has_key(id):
531+
if id in self.menus:
532532
self.menus[id].dispatch(id, item, window, event)
533533
else:
534534
if DEBUG: print "MenuBar.dispatch(%d, %d, %s, %s)" % \
@@ -607,7 +607,7 @@ def dispatch(self, id, item, window, event):
607607
else:
608608
# callback is string
609609
wid = MyFrontWindow()
610-
if wid and self.bar.parent._windows.has_key(wid):
610+
if wid and wid in self.bar.parent._windows:
611611
window = self.bar.parent._windows[wid]
612612
if hasattr(window, "domenu_" + callback):
613613
menuhandler = getattr(window, "domenu_" + callback)

Lib/plat-mac/MiniAEFrame.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ def callback_wrapper(self, _request, _reply):
134134
_class = _attributes['evcl'].type
135135
_type = _attributes['evid'].type
136136

137-
if self.ae_handlers.has_key((_class, _type)):
137+
if (_class, _type) in self.ae_handlers:
138138
_function = self.ae_handlers[(_class, _type)]
139-
elif self.ae_handlers.has_key((_class, '****')):
139+
elif (_class, '****') in self.ae_handlers:
140140
_function = self.ae_handlers[(_class, '****')]
141-
elif self.ae_handlers.has_key(('****', '****')):
141+
elif ('****', '****') in self.ae_handlers:
142142
_function = self.ae_handlers[('****', '****')]
143143
else:
144144
raise 'Cannot happen: AE callback without handler', (_class, _type)
@@ -148,7 +148,7 @@ def callback_wrapper(self, _request, _reply):
148148
_parameters['_attributes'] = _attributes
149149
_parameters['_class'] = _class
150150
_parameters['_type'] = _type
151-
if _parameters.has_key('----'):
151+
if '----' in _parameters:
152152
_object = _parameters['----']
153153
del _parameters['----']
154154
# The try/except that used to be here can mask programmer errors.

Lib/plat-mac/aepack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def unpack(desc, formodulename=""):
129129
"""Unpack an AE descriptor to a python object"""
130130
t = desc.type
131131

132-
if unpacker_coercions.has_key(t):
132+
if t in unpacker_coercions:
133133
desc = desc.AECoerceDesc(unpacker_coercions[t])
134134
t = desc.type # This is a guess by Jack....
135135

Lib/plat-mac/aetools.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def keysubst(arguments, keydict):
107107
"""Replace long name keys by their 4-char counterparts, and check"""
108108
ok = keydict.values()
109109
for k in arguments.keys():
110-
if keydict.has_key(k):
110+
if k in keydict:
111111
v = arguments[k]
112112
del arguments[k]
113113
arguments[keydict[k]] = v
@@ -116,11 +116,11 @@ def keysubst(arguments, keydict):
116116

117117
def enumsubst(arguments, key, edict):
118118
"""Substitute a single enum keyword argument, if it occurs"""
119-
if not arguments.has_key(key) or edict is None:
119+
if key not in arguments or edict is None:
120120
return
121121
v = arguments[key]
122122
ok = edict.values()
123-
if edict.has_key(v):
123+
if v in edict:
124124
arguments[key] = Enum(edict[v])
125125
elif not v in ok:
126126
raise TypeError, 'Unknown enumerator: %s'%v
@@ -129,11 +129,11 @@ def decodeerror(arguments):
129129
"""Create the 'best' argument for a raise MacOS.Error"""
130130
errn = arguments['errn']
131131
err_a1 = errn
132-
if arguments.has_key('errs'):
132+
if 'errs' in arguments:
133133
err_a2 = arguments['errs']
134134
else:
135135
err_a2 = MacOS.GetErrorString(errn)
136-
if arguments.has_key('erob'):
136+
if 'erob' in arguments:
137137
err_a3 = arguments['erob']
138138
else:
139139
err_a3 = None
@@ -248,10 +248,10 @@ def _get(self, _object, asfile=None, _attributes={}):
248248

249249
_reply, _arguments, _attributes = self.send(_code, _subcode,
250250
_arguments, _attributes)
251-
if _arguments.has_key('errn'):
251+
if 'errn' in _arguments:
252252
raise Error, decodeerror(_arguments)
253253

254-
if _arguments.has_key('----'):
254+
if '----' in _arguments:
255255
return _arguments['----']
256256
if asfile:
257257
item.__class__ = asfile
@@ -281,7 +281,7 @@ def _set(self, _object, _attributes={}, **_arguments):
281281
if _arguments.get('errn', 0):
282282
raise Error, decodeerror(_arguments)
283283
# XXXX Optionally decode result
284-
if _arguments.has_key('----'):
284+
if '----' in _arguments:
285285
return _arguments['----']
286286

287287
set = _set
@@ -290,10 +290,10 @@ def _set(self, _object, _attributes={}, **_arguments):
290290
# like the "application" class in OSA.
291291

292292
def __getattr__(self, name):
293-
if self._elemdict.has_key(name):
293+
if name in self._elemdict:
294294
cls = self._elemdict[name]
295295
return DelayedComponentItem(cls, None)
296-
if self._propdict.has_key(name):
296+
if name in self._propdict:
297297
cls = self._propdict[name]
298298
return cls()
299299
raise AttributeError, name
@@ -315,10 +315,10 @@ def open(self, _object, _attributes={}, **_arguments):
315315

316316
_reply, _arguments, _attributes = self.send(_code, _subcode,
317317
_arguments, _attributes)
318-
if _arguments.has_key('errn'):
318+
if 'errn' in _arguments:
319319
raise Error, decodeerror(_arguments)
320320
# XXXX Optionally decode result
321-
if _arguments.has_key('----'):
321+
if '----' in _arguments:
322322
return _arguments['----']
323323
#pass
324324

Lib/plat-mac/aetypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ def __str__(self):
530530
return s
531531

532532
def __getattr__(self, name):
533-
if self._elemdict.has_key(name):
533+
if name in self._elemdict:
534534
cls = self._elemdict[name]
535535
return DelayedComponentItem(cls, self)
536-
if self._propdict.has_key(name):
536+
if name in self._propdict:
537537
cls = self._propdict[name]
538538
return cls(self)
539539
raise AttributeError, name

0 commit comments

Comments
 (0)