Skip to content

Commit 41e1afc

Browse files
committed
Fix some python2.6 -3 warnings. (mainly usage of has_key)
svn path=/trunk/matplotlib/; revision=6143
1 parent 34723f2 commit 41e1afc

29 files changed

+74
-82
lines changed

boilerplate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def %(func)s(*args, **kwargs):
114114

115115

116116
for func in _plotcommands:
117-
if cmappable.has_key(func):
117+
if func in cmappable:
118118
mappable = cmappable[func]
119119
else:
120120
mappable = ''

lib/matplotlib/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def _get_configdir():
443443
def _get_data_path():
444444
'get the path to matplotlib data'
445445

446-
if os.environ.has_key('MATPLOTLIBDATA'):
446+
if 'MATPLOTLIBDATA' in os.environ:
447447
path = os.environ['MATPLOTLIBDATA']
448448
if not os.path.isdir(path):
449449
raise RuntimeError('Path in environment MATPLOTLIBDATA not a directory')
@@ -535,7 +535,7 @@ def matplotlib_fname():
535535
fname = os.path.join( os.getcwd(), 'matplotlibrc')
536536
if os.path.exists(fname): return fname
537537

538-
if os.environ.has_key('MATPLOTLIBRC'):
538+
if 'MATPLOTLIBRC' in os.environ:
539539
path = os.environ['MATPLOTLIBRC']
540540
if os.path.exists(path):
541541
fname = os.path.join(path, 'matplotlibrc')
@@ -637,7 +637,7 @@ def rc_params(fail_on_error=False):
637637
verbose.set_fileo(ret['verbose.fileo'])
638638

639639
for key, (val, line, cnt) in rc_temp.iteritems():
640-
if defaultParams.has_key(key):
640+
if key in defaultParams:
641641
if fail_on_error:
642642
ret[key] = val # try to convert to proper type or raise
643643
else:
@@ -745,7 +745,7 @@ def rc(group, **kwargs):
745745
for k,v in kwargs.items():
746746
name = aliases.get(k) or k
747747
key = '%s.%s' % (g, name)
748-
if not rcParams.has_key(key):
748+
if key not in rcParams:
749749
raise KeyError('Unrecognized key "%s" for group "%s" and name "%s"' %
750750
(key, g, name))
751751

lib/matplotlib/_pylab_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def destroy(num):
3131
destroy = staticmethod(destroy)
3232

3333
def has_fignum(num):
34-
return Gcf.figs.has_key(num)
34+
return num in Gcf.figs
3535
has_fignum = staticmethod(has_fignum)
3636

3737
def get_all_fig_managers():

lib/matplotlib/afm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def _parse_optional(fh):
263263
if len(line)==0: continue
264264
key = line.split()[0]
265265

266-
if optional.has_key(key): d[key] = optional[key](fh)
266+
if key in optional: d[key] = optional[key](fh)
267267

268268
l = ( d['StartKernData'], d['StartComposites'] )
269269
return l

lib/matplotlib/artist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def aliased_name(self, s):
662662
alias, return 'markerfacecolor or mfc' and for the transform
663663
property, which does not, return 'transform'
664664
"""
665-
if self.aliasd.has_key(s):
665+
if s in self.aliasd:
666666
return '%s or %s' % (s, self.aliasd[s])
667667
else: return s
668668

lib/matplotlib/axes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ def _process_plot_format(fmt):
7373
chars = [c for c in fmt]
7474

7575
for c in chars:
76-
if mlines.lineStyles.has_key(c):
76+
if c in mlines.lineStyles:
7777
if linestyle is not None:
7878
raise ValueError(
7979
'Illegal format string "%s"; two linestyle symbols' % fmt)
8080
linestyle = c
81-
elif mlines.lineMarkers.has_key(c):
81+
elif c in mlines.lineMarkers:
8282
if marker is not None:
8383
raise ValueError(
8484
'Illegal format string "%s"; two marker symbols' % fmt)
8585
marker = c
86-
elif mcolors.colorConverter.colors.has_key(c):
86+
elif c in mcolors.colorConverter.colors:
8787
if color is not None:
8888
raise ValueError(
8989
'Illegal format string "%s"; two color symbols' % fmt)
@@ -2632,7 +2632,7 @@ def text(self, x, y, s, fontdict=None,
26322632

26332633

26342634
#if t.get_clip_on(): t.set_clip_box(self.bbox)
2635-
if kwargs.has_key('clip_on'): t.set_clip_box(self.bbox)
2635+
if 'clip_on' in kwargs: t.set_clip_box(self.bbox)
26362636
return t
26372637
text.__doc__ = cbook.dedent(text.__doc__) % martist.kwdocd
26382638

lib/matplotlib/backends/backend_gtk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def motion_notify_event(self, widget, event):
234234
return False # finish event propagation?
235235

236236
def _get_key(self, event):
237-
if self.keyvald.has_key(event.keyval):
237+
if event.keyval in self.keyvald:
238238
key = self.keyvald[event.keyval]
239239
elif event.keyval <256:
240240
key = chr(event.keyval)

lib/matplotlib/backends/backend_qt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def minumumSizeHint( self ):
170170
def _get_key( self, event ):
171171
if event.key() < 256:
172172
key = event.text().latin1()
173-
elif self.keyvald.has_key( event.key() ):
173+
elif event.key() in self.keyvald.has_key:
174174
key = self.keyvald[ event.key() ]
175175
else:
176176
key = None

lib/matplotlib/backends/backend_qt4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def minumumSizeHint( self ):
174174
def _get_key( self, event ):
175175
if event.key() < 256:
176176
key = str(event.text())
177-
elif self.keyvald.has_key( event.key() ):
177+
elif event.key() in self.keyvald:
178178
key = self.keyvald[ event.key() ]
179179
else:
180180
key = None

lib/matplotlib/backends/backend_tkagg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def scroll_event_windows(self, event):
297297

298298
def _get_key(self, event):
299299
val = event.keysym_num
300-
if self.keyvald.has_key(val):
300+
if val in self.keyvald:
301301
key = self.keyvald[val]
302302
elif val<256:
303303
key = chr(val)

lib/matplotlib/backends/backend_wx.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ def _onSize(self, evt):
11411141
def _get_key(self, evt):
11421142

11431143
keyval = evt.m_keyCode
1144-
if self.keyvald.has_key(keyval):
1144+
if keyval in self.keyvald:
11451145
key = self.keyvald[keyval]
11461146
elif keyval <256:
11471147
key = chr(keyval)

lib/matplotlib/collections.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ def set_linestyles(self, ls):
267267
try:
268268
dashd = backend_bases.GraphicsContextBase.dashd
269269
if cbook.is_string_like(ls):
270-
if dashd.has_key(ls):
270+
if ls in dashd:
271271
dashes = [dashd[ls]]
272-
elif cbook.ls_mapper.has_key(ls):
272+
elif ls in cbook.ls_mapper:
273273
dashes = [dashd[cbook.ls_mapper[ls]]]
274274
else:
275275
raise ValueError()
@@ -278,9 +278,9 @@ def set_linestyles(self, ls):
278278
dashes = []
279279
for x in ls:
280280
if cbook.is_string_like(x):
281-
if dashd.has_key(x):
281+
if x in dashd:
282282
dashes.append(dashd[x])
283-
elif cbook.ls_mapper.has_key(x):
283+
elif x in cbook.ls_mapper:
284284
dashes.append(dashd[cbook.ls_mapper[x]])
285285
else:
286286
raise ValueError()

lib/matplotlib/config/cutils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _get_configdir():
9393
def _get_data_path():
9494
'get the path to matplotlib data'
9595

96-
if os.environ.has_key('MATPLOTLIBDATA'):
96+
if 'MATPLOTLIBDATA' in os.environ:
9797
path = os.environ['MATPLOTLIBDATA']
9898
if not os.path.isdir(path):
9999
raise RuntimeError('Path in environment MATPLOTLIBDATA not a directory')
@@ -167,7 +167,7 @@ def get_config_file(tconfig=False):
167167
fname = os.path.join( os.getcwd(), filename)
168168
if os.path.exists(fname): return fname
169169

170-
if os.environ.has_key('MATPLOTLIBRC'):
170+
if 'MATPLOTLIBRC' in os.environ:
171171
path = os.environ['MATPLOTLIBRC']
172172
if os.path.exists(path):
173173
fname = os.path.join(path, filename)

lib/matplotlib/config/mplconfig.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ def __getitem__(self, key):
461461
def keys(self):
462462
return self.tconfig_map.keys()
463463

464-
def has_key(self, val):
465-
return self.tconfig_map.has_key(val)
464+
def __contains__(self, val):
465+
return val in self.tconfig_map
466466

467467
def update(self, arg, **kwargs):
468468
try:

lib/matplotlib/config/rcparams.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919

2020

2121
class RcParams(dict):
22-
22+
2323
"""A dictionary object including validation
24-
24+
2525
validating functions are defined and associated with rc parameters in
2626
rcsetup.py
2727
"""
28-
28+
2929
validate = dict([ (key, converter) for key, (default, converter) in \
3030
defaultParams.iteritems() ])
31-
31+
3232
def __setitem__(self, key, val):
3333
try:
3434
if key in _deprecated_map.keys():
@@ -89,7 +89,7 @@ def rc_params(fail_on_error=False):
8989
verbose.set_fileo(ret['verbose.fileo'])
9090

9191
for key, (val, line, cnt) in rc_temp.iteritems():
92-
if defaultParams.has_key(key):
92+
if key in defaultParams:
9393
if fail_on_error:
9494
ret[key] = val # try to convert to proper type or raise
9595
else:
@@ -109,7 +109,7 @@ def rc_params(fail_on_error=False):
109109
ret['datapath'] = get_data_path()
110110

111111
verbose.report('loaded rc file %s'%fname)
112-
112+
113113
return ret
114114

115115

@@ -183,7 +183,7 @@ def rc(group, **kwargs):
183183
for k,v in kwargs.items():
184184
name = aliases.get(k) or k
185185
key = '%s.%s' % (g, name)
186-
if not rcParams.has_key(key):
186+
if key not in rcParams:
187187
raise KeyError('Unrecognized key "%s" for group "%s" and name "%s"' %
188188
(key, g, name))
189189

lib/matplotlib/figure.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def add_axes(self, *args, **kwargs):
591591

592592
key = self._make_key(*args, **kwargs)
593593

594-
if self._seen.has_key(key):
594+
if key in self._seen:
595595
ax = self._seen[key]
596596
self.sca(ax)
597597
return ax
@@ -652,7 +652,7 @@ def add_subplot(self, *args, **kwargs):
652652
"""
653653

654654
key = self._make_key(*args, **kwargs)
655-
if self._seen.has_key(key):
655+
if key in self._seen:
656656
ax = self._seen[key]
657657
self.sca(ax)
658658
return ax
@@ -951,7 +951,7 @@ def savefig(self, *args, **kwargs):
951951
"""
952952

953953
for key in ('dpi', 'facecolor', 'edgecolor'):
954-
if not kwargs.has_key(key):
954+
if key not in kwargs:
955955
kwargs[key] = rcParams['savefig.%s'%key]
956956

957957
transparent = kwargs.pop('transparent', False)

lib/matplotlib/font_manager.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def createFontDict(fontfiles, fontext='ttf'):
505505
for fpath in fontfiles:
506506
verbose.report('createFontDict: %s' % (fpath), 'debug')
507507
fname = os.path.split(fpath)[1]
508-
if seen.has_key(fname): continue
508+
if fname in seen: continue
509509
else: seen[fname] = 1
510510
if fontext == 'afm':
511511
try:
@@ -552,33 +552,33 @@ def setWeights(font):
552552
for j in range(100, 1000, 100):
553553
font[j] = temp[wgt]
554554

555-
if temp.has_key(400):
555+
if 400 in temp:
556556
for j in range(100, 1000, 100):
557557
font[j] = temp[400]
558-
if temp.has_key(500):
559-
if temp.has_key(400):
558+
if 500 in temp:
559+
if 400 in temp:
560560
for j in range(500, 1000, 100):
561561
font[j] = temp[500]
562562
else:
563563
for j in range(100, 1000, 100):
564564
font[j] = temp[500]
565565

566-
if temp.has_key(300):
566+
if 300 in temp:
567567
for j in [100, 200, 300]:
568568
font[j] = temp[300]
569-
if temp.has_key(200):
570-
if temp.has_key(300):
569+
if 200 in temp:
570+
if 300 in temp:
571571
for j in [100, 200]:
572572
font[j] = temp[200]
573573
else:
574574
for j in [100, 200, 300]:
575575
font[j] = temp[200]
576576

577-
if temp.has_key(800):
577+
if 800 in temp:
578578
for j in [600, 700, 800, 900]:
579579
font[j] = temp[800]
580-
if temp.has_key(700):
581-
if temp.has_key(800):
580+
if 700 in temp:
581+
if 800 in temp:
582582
for j in [600, 700]:
583583
font[j] = temp[700]
584584
else:
@@ -872,7 +872,7 @@ def __init__(self, size=None, weight='normal'):
872872
# Create list of font paths
873873

874874
for pathname in ['TTFPATH', 'AFMPATH']:
875-
if os.environ.has_key(pathname):
875+
if pathname in os.environ:
876876
ttfpath = os.environ[pathname]
877877
if ttfpath.find(';') >= 0: #win32 style
878878
paths.extend(ttfpath.split(';'))
@@ -983,50 +983,50 @@ def lookup_name(name):
983983

984984
fname = None
985985
font = fontdict
986-
if font.has_key(name):
986+
if name in font:
987987
font = font[name]
988988
else:
989989
verbose.report('\tfindfont failed %(name)s'%locals(), 'debug')
990990
return None
991991

992-
if font.has_key(style):
992+
if style in font:
993993
font = font[style]
994-
elif style == 'italic' and font.has_key('oblique'):
994+
elif style == 'italic' and 'oblique' in font:
995995
font = font['oblique']
996-
elif style == 'oblique' and font.has_key('italic'):
996+
elif style == 'oblique' and 'italic' in font:
997997
font = font['italic']
998998
else:
999999
verbose.report('\tfindfont failed %(name)s, %(style)s'%locals(), 'debug')
10001000
return None
10011001

1002-
if font.has_key(variant):
1002+
if variant in font:
10031003
font = font[variant]
10041004
else:
10051005
verbose.report('\tfindfont failed %(name)s, %(style)s, %(variant)s'%locals(), 'debug')
10061006
return None
10071007

1008-
if not font.has_key(weight):
1008+
if weight in font:
10091009
setWeights(font)
1010-
if not font.has_key(weight):
1010+
if weight not in font:
10111011
return None
10121012
font = font[weight]
10131013

1014-
if font.has_key(stretch):
1014+
if stretch in font:
10151015
stretch_font = font[stretch]
1016-
if stretch_font.has_key('scalable'):
1016+
if 'scalable' in stretch_font:
10171017
fname = stretch_font['scalable']
1018-
elif stretch_font.has_key(size):
1018+
elif size in stretch_font:
10191019
fname = stretch_font[size]
10201020

10211021
if fname is None:
10221022
for val in font.values():
1023-
if val.has_key('scalable'):
1023+
if 'scalable' in val:
10241024
fname = val['scalable']
10251025
break
10261026

10271027
if fname is None:
10281028
for val in font.values():
1029-
if val.has_key(size):
1029+
if size in val:
10301030
fname = val[size]
10311031
break
10321032

0 commit comments

Comments
 (0)