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

Skip to content

Commit 58b6dc6

Browse files
committed
Iterating over a dict is easy.
1 parent de2836d commit 58b6dc6

21 files changed

+47
-74
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,4 +1894,4 @@ def inner(ax, *args, **kwargs):
18941894
verbose.report('verbose.level %s' % verbose.level)
18951895
verbose.report('interactive is %s' % is_interactive())
18961896
verbose.report('platform is %s' % sys.platform)
1897-
verbose.report('loaded modules: %s' % six.iterkeys(sys.modules), 'debug')
1897+
verbose.report('loaded modules: %s' % list(sys.modules), 'debug')

lib/matplotlib/artist.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,12 +1396,8 @@ def pprint_getters(self):
13961396
Return the getters and actual values as list of strings.
13971397
"""
13981398

1399-
d = self.properties()
1400-
names = list(six.iterkeys(d))
1401-
names.sort()
14021399
lines = []
1403-
for name in names:
1404-
val = d[name]
1400+
for name, val in sorted(six.iteritems(self.properties())):
14051401
if getattr(val, 'shape', ()) != () and len(val) > 6:
14061402
s = str(val[:6]) + '...'
14071403
else:

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,12 +1327,11 @@ def set_anchor(self, anchor):
13271327
===== ============
13281328
13291329
"""
1330-
if (anchor in list(six.iterkeys(mtransforms.Bbox.coefs)) or
1331-
len(anchor) == 2):
1330+
if anchor in mtransforms.Bbox.coefs or len(anchor) == 2:
13321331
self._anchor = anchor
13331332
else:
13341333
raise ValueError('argument must be among %s' %
1335-
', '.join(six.iterkeys(mtransforms.Bbox.coefs)))
1334+
', '.join(mtransforms.Bbox.coefs))
13361335
self.stale = True
13371336

13381337
def get_data_ratio(self):
@@ -2888,8 +2887,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
28882887
if 'xmax' in kw:
28892888
right = kw.pop('xmax')
28902889
if kw:
2891-
raise ValueError("unrecognized kwargs: %s" %
2892-
list(six.iterkeys(kw)))
2890+
raise ValueError("unrecognized kwargs: %s" % list(kw))
28932891

28942892
if right is None and iterable(left):
28952893
left, right = left
@@ -3169,8 +3167,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
31693167
if 'ymax' in kw:
31703168
top = kw.pop('ymax')
31713169
if kw:
3172-
raise ValueError("unrecognized kwargs: %s" %
3173-
list(six.iterkeys(kw)))
3170+
raise ValueError("unrecognized kwargs: %s" % list(kw))
31743171

31753172
if top is None and iterable(bottom):
31763173
bottom, top = bottom

lib/matplotlib/backends/backend_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ def is_date(x):
15101510
'CreationDate': is_date,
15111511
'ModDate': is_date,
15121512
'Trapped': check_trapped}
1513-
for k in six.iterkeys(self.infoDict):
1513+
for k in self.infoDict:
15141514
if k not in keywords:
15151515
warnings.warn('Unknown infodict keyword: %s' % k)
15161516
else:

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,8 @@ def _print_ps(self, outfile, format, *args, **kwargs):
958958
if papertype == 'auto':
959959
pass
960960
elif papertype not in papersize:
961-
raise RuntimeError( '%s is not a valid papertype. Use one \
962-
of %s'% (papertype, ', '.join(six.iterkeys(papersize))))
961+
raise RuntimeError('%s is not a valid papertype. Use one of %s' %
962+
(papertype, ', '.join(papersize)))
963963

964964
orientation = kwargs.pop("orientation", "portrait").lower()
965965
if orientation == 'landscape': isLandscape = True

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
593593
style = self._get_style_dict(gc, rgbFace)
594594
dictkey = (path_data, generate_css(style))
595595
oid = self._markers.get(dictkey)
596-
for key in list(six.iterkeys(style)):
596+
for key in style:
597597
if not key.startswith('stroke'):
598598
del style[key]
599599
style = generate_css(style)

lib/matplotlib/cbook.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,13 @@ def __init__(self, **kwds):
651651
self.__dict__.update(kwds)
652652

653653
def __repr__(self):
654-
keys = six.iterkeys(self.__dict__)
655-
return 'Bunch(%s)' % ', '.join(['%s=%s' % (k, self.__dict__[k])
656-
for k
657-
in keys])
654+
return 'Bunch(%s)' % ', '.join(
655+
'%s=%s' % kv for kv in six.iteritems(vars(self)))
658656

659657

660658
def unique(x):
661659
"""Return a list of unique elements of *x*"""
662-
return list(six.iterkeys(dict([(val, 1) for val in x])))
660+
return list(set(x))
663661

664662

665663
def iterable(obj):
@@ -920,7 +918,7 @@ class Xlator(dict):
920918

921919
def _make_regex(self):
922920
""" Build re object based on the keys of the current dictionary """
923-
return re.compile("|".join(map(re.escape, list(six.iterkeys(self)))))
921+
return re.compile("|".join(map(re.escape, self)))
924922

925923
def __call__(self, match):
926924
""" Handler invoked for each regex *match* """

lib/matplotlib/cm.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,13 @@ def _generate_cmap(name, lutsize):
8686
with _warnings.catch_warnings():
8787
_warnings.simplefilter("ignore")
8888
# Generate the reversed specifications ...
89-
for cmapname in list(six.iterkeys(datad)):
90-
spec = datad[cmapname]
91-
spec_reversed = _reverse_cmap_spec(spec)
92-
datad[cmapname + '_r'] = spec_reversed
89+
for cmapname, spec in list(six.iteritems(datad)):
90+
datad[cmapname + '_r'] = _reverse_cmap_spec(spec)
9391

9492
# Precache the cmaps with ``lutsize = LUTSIZE`` ...
9593

96-
# Use datad.keys() to also add the reversed ones added in the section
97-
# above:
98-
for cmapname in six.iterkeys(datad):
94+
# Also add the reversed ones added in the section above:
95+
for cmapname in datad:
9996
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
10097

10198
cmap_d.update(cmaps_listed)

lib/matplotlib/dviread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def __init__(self, scale, tfm, texname, vf):
532532
scale, tfm, texname, vf
533533
self.size = scale * (72.0 / (72.27 * 2**16))
534534
try:
535-
nchars = max(six.iterkeys(tfm.width)) + 1
535+
nchars = max(tfm.width) + 1
536536
except ValueError:
537537
nchars = 0
538538
self.widths = [(1000*tfm.width.get(char, 0)) >> 20

lib/matplotlib/font_manager.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
240240
continue
241241
except MemoryError:
242242
continue
243-
return list(six.iterkeys(items))
243+
return list(items)
244244
finally:
245245
winreg.CloseKey(local)
246246
return None
@@ -335,7 +335,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
335335
for fname in files:
336336
fontfiles[os.path.abspath(fname)] = 1
337337

338-
return [fname for fname in six.iterkeys(fontfiles) if os.path.exists(fname)]
338+
return [fname for fname in fontfiles if os.path.exists(fname)]
339339

340340
def weight_as_number(weight):
341341
"""
@@ -431,11 +431,7 @@ def ttfFontProperty(font):
431431
# 600 (semibold, demibold), 700 (bold), 800 (heavy), 900 (black)
432432
# lighter and bolder are also allowed.
433433

434-
weight = None
435-
for w in six.iterkeys(weight_dict):
436-
if sfnt4.find(w) >= 0:
437-
weight = w
438-
break
434+
weight = next((w for w in weight_dict if sfnt4.find(w) >= 0), None)
439435
if not weight:
440436
if font.style_flags & ft2font.BOLD:
441437
weight = 700

lib/matplotlib/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
'blackman': _image.BLACKMAN,
5757
}
5858

59-
interpolations_names = set(six.iterkeys(_interpd_))
59+
interpolations_names = set(_interpd_)
6060

6161

6262
def composite_images(images, renderer, magnification=1.0):
@@ -1224,7 +1224,7 @@ def pilread(fname):
12241224
if im is None:
12251225
raise ValueError('Only know how to handle extensions: %s; '
12261226
'with Pillow installed matplotlib can handle '
1227-
'more images' % list(six.iterkeys(handlers)))
1227+
'more images' % list(handlers))
12281228
return im
12291229

12301230
handler = handlers[ext]

lib/matplotlib/legend.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,13 @@ def __init__(self, parent, handles, labels,
323323
if self.isaxes:
324324
warnings.warn('Unrecognized location "%s". Falling back '
325325
'on "best"; valid locations are\n\t%s\n'
326-
% (loc, '\n\t'.join(
327-
six.iterkeys(self.codes))))
326+
% (loc, '\n\t'.join(self.codes)))
328327
loc = 0
329328
else:
330329
warnings.warn('Unrecognized location "%s". Falling back '
331330
'on "upper right"; '
332331
'valid locations are\n\t%s\n'
333-
% (loc, '\n\t'.join(
334-
six.iterkeys(self.codes))))
332+
% (loc, '\n\t'.join(self.codes)))
335333
loc = 1
336334
else:
337335
loc = self.codes[loc]

lib/matplotlib/lines.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ class Line2D(Artist):
264264
drawStyles.update(_drawStyles_l)
265265
drawStyles.update(_drawStyles_s)
266266
# Need a list ordered with long names first:
267-
drawStyleKeys = (list(six.iterkeys(_drawStyles_l)) +
268-
list(six.iterkeys(_drawStyles_s)))
267+
drawStyleKeys = list(_drawStyles_l) + list(_drawStyles_s)
269268

270269
# Referenced here to maintain API. These are defined in
271270
# MarkerStyle

lib/matplotlib/mathtext.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ def __init__(self):
23582358
p.rbracket <<= Literal(']').suppress()
23592359
p.bslash <<= Literal('\\')
23602360

2361-
p.space <<= oneOf(list(six.iterkeys(self._space_widths)))
2361+
p.space <<= oneOf(list(self._space_widths))
23622362
p.customspace <<= (Suppress(Literal(r'\hspace'))
23632363
- ((p.lbrace + p.float_literal + p.rbrace)
23642364
| Error(r"Expected \hspace{n}")))
@@ -2367,17 +2367,17 @@ def __init__(self):
23672367
p.single_symbol <<= Regex(r"([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])" %
23682368
unicode_range)
23692369
p.snowflake <<= Suppress(p.bslash) + oneOf(self._snowflake)
2370-
p.symbol_name <<= (Combine(p.bslash + oneOf(list(six.iterkeys(tex2uni)))) +
2370+
p.symbol_name <<= (Combine(p.bslash + oneOf(list(tex2uni))) +
23712371
FollowedBy(Regex("[^A-Za-z]").leaveWhitespace() | StringEnd()))
23722372
p.symbol <<= (p.single_symbol | p.symbol_name).leaveWhitespace()
23732373

23742374
p.apostrophe <<= Regex("'+")
23752375

2376-
p.c_over_c <<= Suppress(p.bslash) + oneOf(list(six.iterkeys(self._char_over_chars)))
2376+
p.c_over_c <<= Suppress(p.bslash) + oneOf(list(self._char_over_chars))
23772377

23782378
p.accent <<= Group(
23792379
Suppress(p.bslash)
2380-
+ oneOf(list(six.iterkeys(self._accent_map)) + list(self._wide_accents))
2380+
+ oneOf(list(self._accent_map) + list(self._wide_accents))
23812381
- p.placeable
23822382
)
23832383

lib/matplotlib/mlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,7 @@ def mapped_r2field(name):
25762576

25772577
if jointype != 'inner' and defaults is not None:
25782578
# fill in the defaults enmasse
2579-
newrec_fields = list(six.iterkeys(newrec.dtype.fields))
2579+
newrec_fields = list(newrec.dtype.fields)
25802580
for k, v in six.iteritems(defaults):
25812581
if k in newrec_fields:
25822582
newrec[k] = v

lib/matplotlib/offsetbox.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,20 +1237,16 @@ def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
12371237

12381238
if prop is None:
12391239
prop = {}
1240-
propkeys = list(six.iterkeys(prop))
1241-
badkwargs = ('ha', 'horizontalalignment', 'va', 'verticalalignment')
1242-
if set(badkwargs) & set(propkeys):
1240+
badkwargs = {'ha', 'horizontalalignment', 'va', 'verticalalignment'}
1241+
if badkwargs & set(prop):
12431242
warnings.warn("Mixing horizontalalignment or verticalalignment "
1244-
"with AnchoredText is not supported.")
1243+
"with AnchoredText is not supported.")
12451244

1246-
self.txt = TextArea(s, textprops=prop,
1247-
minimumdescent=False)
1245+
self.txt = TextArea(s, textprops=prop, minimumdescent=False)
12481246
fp = self.txt._text.get_fontproperties()
1249-
1250-
super(AnchoredText, self).__init__(loc, pad=pad, borderpad=borderpad,
1251-
child=self.txt,
1252-
prop=fp,
1253-
**kwargs)
1247+
super(AnchoredText, self).__init__(
1248+
loc, pad=pad, borderpad=borderpad, child=self.txt, prop=fp,
1249+
**kwargs)
12541250

12551251

12561252
class OffsetImage(OffsetBox):

lib/matplotlib/path.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,7 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
203203
if internals:
204204
raise ValueError('Unexpected internals provided to '
205205
'_fast_from_codes_and_verts: '
206-
'{0}'.format('\n *'.join(six.iterkeys(
207-
internals
208-
))))
206+
'{0}'.format('\n *'.join(internals)))
209207
return pth
210208

211209
def _update_values(self):

lib/matplotlib/table.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
256256
if is_string_like(loc) and loc not in self.codes:
257257
warnings.warn('Unrecognized location %s. Falling back on '
258258
'bottom; valid locations are\n%s\t' %
259-
(loc, '\n\t'.join(six.iterkeys(self.codes))))
259+
(loc, '\n\t'.join(self.codes)))
260260
loc = 'bottom'
261261
if is_string_like(loc):
262262
loc = self.codes.get(loc, 1)
@@ -328,8 +328,7 @@ def _get_grid_bbox(self, renderer):
328328
329329
Only include those in the range (0,0) to (maxRow, maxCol)"""
330330
boxes = [self._cells[pos].get_window_extent(renderer)
331-
for pos in six.iterkeys(self._cells)
332-
if pos[0] >= 0 and pos[1] >= 0]
331+
for pos in self._cells if pos[0] >= 0 and pos[1] >= 0]
333332

334333
bbox = Bbox.union(boxes)
335334
return bbox.inverse_transformed(self.get_transform())
@@ -347,8 +346,7 @@ def contains(self, mouseevent):
347346
renderer = self.figure._cachedRenderer
348347
if renderer is not None:
349348
boxes = [self._cells[pos].get_window_extent(renderer)
350-
for pos in six.iterkeys(self._cells)
351-
if pos[0] >= 0 and pos[1] >= 0]
349+
for pos in self._cells if pos[0] >= 0 and pos[1] >= 0]
352350
bbox = Bbox.union(boxes)
353351
return bbox.contains(mouseevent.x, mouseevent.y), {}
354352
else:

lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def comparable_formats():
157157
on this system.
158158
159159
"""
160-
return ['png'] + list(six.iterkeys(converter))
160+
return ['png'] + list(converter)
161161

162162

163163
def convert(filename, cache):

lib/matplotlib/tests/test_colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def test_pandas_iterable():
612612
def test_colormap_reversing():
613613
"""Check the generated _lut data of a colormap and corresponding
614614
reversed colormap if they are almost the same."""
615-
for name in six.iterkeys(cm.cmap_d):
615+
for name in cm.cmap_d:
616616
cmap = plt.get_cmap(name)
617617
cmap_r = cmap.reversed()
618618
if not cmap_r._isinit:

lib/matplotlib/tests/test_rcparams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_RcParams_class():
113113

114114
# test the find_all functionality
115115
assert ['font.cursive', 'font.size'] == sorted(rc.find_all('i[vz]').keys())
116-
assert ['font.family'] == list(six.iterkeys(rc.find_all('family')))
116+
assert ['font.family'] == list(rc.find_all('family'))
117117

118118

119119
def test_rcparams_update():
@@ -153,7 +153,7 @@ def test_Bug_2543():
153153
category=UserWarning)
154154
with mpl.rc_context():
155155
_copy = mpl.rcParams.copy()
156-
for key in six.iterkeys(_copy):
156+
for key in _copy:
157157
mpl.rcParams[key] = _copy[key]
158158
mpl.rcParams['text.dvipnghack'] = None
159159
with mpl.rc_context():

0 commit comments

Comments
 (0)