Skip to content

Commit 69622dd

Browse files
committedDec 4, 2016
set/dict literals/comprehensions.
1 parent 3d00576 commit 69622dd

29 files changed

+70
-88
lines changed
 

‎boilerplate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def format_value(value):
317317
# A gensym-like facility in case some function takes an
318318
# argument named washold, ax, or ret
319319
washold, ret, ax = 'washold', 'ret', 'ax'
320-
bad = set(args) | set((varargs, varkw))
320+
bad = set(args) | {varargs, varkw}
321321
while washold in bad or ret in bad or ax in bad:
322322
washold = 'washold' + str(random.randrange(10 ** 12))
323323
ret = 'ret' + str(random.randrange(10 ** 12))

‎doc/sphinxext/gen_gallery.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ def gen_gallery(app, doctree):
7676
# images we want to skip for the gallery because they are an unusual
7777
# size that doesn't layout well in a table, or because they may be
7878
# redundant with other images or uninteresting
79-
skips = set([
80-
'mathtext_examples',
81-
'matshow_02',
82-
'matshow_03',
83-
'matplotlib_icon',
84-
])
79+
skips = {'mathtext_examples',
80+
'matshow_02',
81+
'matshow_03',
82+
'matplotlib_icon'}
8583

8684
thumbnails = {}
8785
rows = []

‎examples/pylab_examples/arrow_demo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
rates_to_bases = {'r1': 'AT', 'r2': 'TA', 'r3': 'GA', 'r4': 'AG', 'r5': 'CA',
1515
'r6': 'AC', 'r7': 'GT', 'r8': 'TG', 'r9': 'CT', 'r10': 'TC',
1616
'r11': 'GC', 'r12': 'CG'}
17-
numbered_bases_to_rates = dict([(v, k) for k, v in rates_to_bases.items()])
18-
lettered_bases_to_rates = dict([(v, 'r' + v) for k, v in rates_to_bases.items()])
17+
numbered_bases_to_rates = {v: k for k, v in rates_to_bases.items()}
18+
lettered_bases_to_rates = {v: 'r' + v for k, v in rates_to_bases.items()}
1919

2020

2121
def add_dicts(d1, d2):

‎examples/tests/backend_driver.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,13 @@ def report_missing(dir, flist):
321321
globstr = os.path.join(dir, '*.py')
322322
fnames = glob.glob(globstr)
323323

324-
pyfiles = set([os.path.split(fullpath)[-1] for fullpath in set(fnames)])
324+
pyfiles = {os.path.split(fullpath)[-1] for fullpath in set(fnames)}
325325

326326
exclude = set(excluded.get(dir, []))
327327
flist = set(flist)
328328
missing = list(pyfiles - flist - exclude)
329-
missing.sort()
330329
if missing:
331-
print('%s files not tested: %s' % (dir, ', '.join(missing)))
330+
print('%s files not tested: %s' % (dir, ', '.join(sorted(missing))))
332331

333332

334333
def report_all_missing(directories):

‎lib/matplotlib/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class Verbose(object):
263263
instance to handle the output. Default is sys.stdout
264264
"""
265265
levels = ('silent', 'helpful', 'debug', 'debug-annoying')
266-
vald = dict([(level, i) for i, level in enumerate(levels)])
266+
vald = {level: i for i, level in enumerate(levels)}
267267

268268
# parse the verbosity from the command line; flags look like
269269
# --verbose-silent or --verbose-helpful
@@ -860,10 +860,10 @@ def matplotlib_fname():
860860
_deprecated_ignore_map = {
861861
}
862862

863-
_obsolete_set = set(['tk.pythoninspect', 'legend.isaxes'])
863+
_obsolete_set = {'tk.pythoninspect', 'legend.isaxes'}
864864

865865
# The following may use a value of None to suppress the warning.
866-
_deprecated_set = set(['axes.hold']) # do NOT include in _all_deprecated
866+
_deprecated_set = {'axes.hold'} # do NOT include in _all_deprecated
867867

868868
_all_deprecated = set(chain(_deprecated_ignore_map,
869869
_deprecated_map,

‎lib/matplotlib/axes/_base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def _getdefaults(self, ignore, *kwargs):
263263
"""
264264
prop_keys = self._prop_keys
265265
if ignore is None:
266-
ignore = set([])
266+
ignore = set()
267267
prop_keys = prop_keys - ignore
268268

269269
if any(all(kw.get(k, None) is None for kw in kwargs)
@@ -309,8 +309,8 @@ def _makefill(self, x, y, kw, kwargs):
309309
# *user* explicitly specifies a marker which should be an error.
310310
# We also want to prevent advancing the cycler if there are no
311311
# defaults needed after ignoring the given properties.
312-
ignores = set(['marker', 'markersize', 'markeredgecolor',
313-
'markerfacecolor', 'markeredgewidth'])
312+
ignores = {'marker', 'markersize', 'markeredgecolor',
313+
'markerfacecolor', 'markeredgewidth'}
314314
# Also ignore anything provided by *kwargs*.
315315
for k, v in six.iteritems(kwargs):
316316
if v is not None:

‎lib/matplotlib/axis.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ def _apply_params(self, **kw):
324324
self.label1.set_transform(trans)
325325
trans = self._get_text2_transform()[0]
326326
self.label2.set_transform(trans)
327-
tick_kw = dict([kv for kv in six.iteritems(kw)
328-
if kv[0] in ['color', 'zorder']])
327+
tick_kw = {k: v for k, v in six.iteritems(kw)
328+
if k in ['color', 'zorder']}
329329
if tick_kw:
330330
self.tick1line.set(**tick_kw)
331331
self.tick2line.set(**tick_kw)
@@ -334,7 +334,7 @@ def _apply_params(self, **kw):
334334
label_list = [k for k in six.iteritems(kw)
335335
if k[0] in ['labelsize', 'labelcolor', 'labelrotation']]
336336
if label_list:
337-
label_kw = dict([(k[5:], v) for (k, v) in label_list])
337+
label_kw = {k[5:]: v for k, v in label_list}
338338
self.label1.set(**label_kw)
339339
self.label2.set(**label_kw)
340340
for k, v in six.iteritems(label_kw):

‎lib/matplotlib/backends/backend_gtk.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -905,25 +905,26 @@ class DialogLineprops(object):
905905
)
906906

907907
linestyles = [ls for ls in lines.Line2D.lineStyles if ls.strip()]
908-
linestyled = dict([ (s,i) for i,s in enumerate(linestyles)])
908+
linestyled = {s: i for i, s in enumerate(linestyles)}
909909

910-
911-
markers = [m for m in markers.MarkerStyle.markers if cbook.is_string_like(m)]
912-
913-
markerd = dict([(s,i) for i,s in enumerate(markers)])
910+
markers = [m for m in markers.MarkerStyle.markers
911+
if cbook.is_string_like(m)]
912+
markerd = {s: i for i, s in enumerate(markers)}
914913

915914
def __init__(self, lines):
916915
import gtk.glade
917916

918917
datadir = matplotlib.get_data_path()
919918
gladefile = os.path.join(datadir, 'lineprops.glade')
920919
if not os.path.exists(gladefile):
921-
raise IOError('Could not find gladefile lineprops.glade in %s'%datadir)
920+
raise IOError(
921+
'Could not find gladefile lineprops.glade in %s' % datadir)
922922

923923
self._inited = False
924924
self._updateson = True # suppress updates when setting widgets manually
925925
self.wtree = gtk.glade.XML(gladefile, 'dialog_lineprops')
926-
self.wtree.signal_autoconnect(dict([(s, getattr(self, s)) for s in self.signals]))
926+
self.wtree.signal_autoconnect(
927+
{s: getattr(self, s) for s in self.signals})
927928

928929
self.dlg = self.wtree.get_widget('dialog_lineprops')
929930

@@ -947,7 +948,6 @@ def __init__(self, lines):
947948
self._lastcnt = 0
948949
self._inited = True
949950

950-
951951
def show(self):
952952
'populate the combo box'
953953
self._updateson = False
@@ -971,7 +971,6 @@ def get_active_line(self):
971971
line = self.lines[ind]
972972
return line
973973

974-
975974
def get_active_linestyle(self):
976975
'get the active lineinestyle'
977976
ind = self.cbox_linestyles.get_active()
@@ -1005,8 +1004,6 @@ def _update(self):
10051004

10061005
line.figure.canvas.draw()
10071006

1008-
1009-
10101007
def on_combobox_lineprops_changed(self, item):
10111008
'update the widgets from the active line'
10121009
if not self._inited: return

‎lib/matplotlib/backends/backend_pdf.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ def pdfRepr(self):
318318
grestore=b'Q', textpos=b'Td', selectfont=b'Tf', textmatrix=b'Tm',
319319
show=b'Tj', showkern=b'TJ', setlinewidth=b'w', clip=b'W', shading=b'sh')
320320

321-
Op = Bunch(**dict([(name, Operator(value))
322-
for name, value in six.iteritems(_pdfops)]))
321+
Op = Bunch(**{name: Operator(value) for name, value in six.iteritems(_pdfops)})
323322

324323

325324
def _paint_path(fill, stroke):
@@ -556,9 +555,9 @@ def close(self):
556555
self.endStream()
557556
# Write out the various deferred objects
558557
self.writeFonts()
559-
self.writeObject(self.alphaStateObject,
560-
dict([(val[0], val[1])
561-
for val in six.itervalues(self.alphaStates)]))
558+
self.writeObject(
559+
self.alphaStateObject,
560+
{val[0]: val[1] for val in six.itervalues(self.alphaStates)})
562561
self.writeHatches()
563562
self.writeGouraudTriangles()
564563
xobjects = dict(x[1:] for x in six.itervalues(self._images))

‎lib/matplotlib/backends/qt_editor/formlayout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
5757

5858

59-
BLACKLIST = set(["title", "label"])
59+
BLACKLIST = {"title", "label"}
6060

6161

6262
class ColorButton(QtWidgets.QPushButton):

‎lib/matplotlib/cbook.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def __repr__(self):
658658

659659
def unique(x):
660660
"""Return a list of unique elements of *x*"""
661-
return list(six.iterkeys(dict([(val, 1) for val in x])))
661+
return list(set(x))
662662

663663

664664
def iterable(obj):
@@ -1407,15 +1407,15 @@ def finddir(o, match, case=False):
14071407

14081408
def reverse_dict(d):
14091409
"""reverse the dictionary -- may lose data if values are not unique!"""
1410-
return dict([(v, k) for k, v in six.iteritems(d)])
1410+
return {v: k for k, v in six.iteritems(d)}
14111411

14121412

14131413
def restrict_dict(d, keys):
14141414
"""
14151415
Return a dictionary that contains those keys that appear in both
14161416
d and keys, with values from d.
14171417
"""
1418-
return dict([(k, v) for (k, v) in six.iteritems(d) if k in keys])
1418+
return {k: v for k, v in six.iteritems(d) if k in keys}
14191419

14201420

14211421
def report_memory(i=0): # argument may go away
@@ -2077,7 +2077,7 @@ def unmasked_index_ranges(mask, compressed=True):
20772077
# The ls_mapper maps short codes for line style to their full name used
20782078
# by backends
20792079
# The reverse mapper is for mapping full names to short ones
2080-
ls_mapper_r = dict([(ls[1], ls[0]) for ls in _linestyles])
2080+
ls_mapper_r = reverse_dict(ls_mapper)
20812081

20822082

20832083
def align_iterators(func, *iterables):

‎lib/matplotlib/figure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def get(self, key):
9595
return item[1]
9696

9797
def _entry_from_axes(self, e):
98-
ind, k = dict([(a, (ind, k)) for (k, (ind, a)) in self._elements])[e]
98+
ind, k = {a: (ind, k) for k, (ind, a) in self._elements}[e]
9999
return (k, (ind, e))
100100

101101
def remove(self, a):

‎lib/matplotlib/font_manager.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@
108108
'extra bold' : 800,
109109
'black' : 900}
110110

111-
font_family_aliases = set([
112-
'serif',
113-
'sans-serif',
114-
'sans serif',
115-
'cursive',
116-
'fantasy',
117-
'monospace',
118-
'sans'])
111+
font_family_aliases = {
112+
'serif',
113+
'sans-serif',
114+
'sans serif',
115+
'cursive',
116+
'fantasy',
117+
'monospace',
118+
'sans'}
119119

120120
# OS Font paths
121121
MSFolders = \

‎lib/matplotlib/gridspec.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ def update(self, **kwargs):
255255
ax.update_params()
256256
ax.set_position(ax.figbox)
257257

258-
259-
260258
def get_subplot_params(self, fig=None):
261259
"""
262260
return a dictionary of subplot layout parameters. The default
@@ -265,13 +263,12 @@ def get_subplot_params(self, fig=None):
265263
from matplotlib.figure import SubplotParams
266264
import copy
267265
if fig is None:
268-
kw = dict([(k, rcParams["figure.subplot."+k]) \
269-
for k in self._AllowedKeys])
266+
kw = {k: rcParams["figure.subplot."+k] for k in self._AllowedKeys}
270267
subplotpars = SubplotParams(**kw)
271268
else:
272269
subplotpars = copy.copy(fig.subplotpars)
273270

274-
update_kw = dict([(k, getattr(self, k)) for k in self._AllowedKeys])
271+
update_kw = {k: getattr(self, k) for k in self._AllowedKeys}
275272
subplotpars.update(**update_kw)
276273

277274
return subplotpars
@@ -428,7 +425,6 @@ def get_position(self, fig, return_all=False):
428425
figBottoms, figTops, figLefts, figRights = \
429426
gridspec.get_grid_positions(fig)
430427

431-
432428
rowNum, colNum = divmod(self.num1, ncols)
433429
figBottom = figBottoms[rowNum]
434430
figTop = figTops[rowNum]

‎lib/matplotlib/image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class _ImageBase(martist.Artist, cm.ScalarMappable):
186186
# backward compatibility just in case.
187187
_interpd = _interpd_
188188
# reverse interp dict
189-
_interpdr = dict([(v, k) for k, v in six.iteritems(_interpd_)])
189+
_interpdr = {v: k for k, v in six.iteritems(_interpd_)}
190190
iterpnames = interpolations_names
191191
# <end unused keys>
192192

‎lib/matplotlib/mathtext.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@ def __init__(self):
24102410
p.ambi_delim <<= oneOf(list(self._ambi_delim))
24112411
p.left_delim <<= oneOf(list(self._left_delim))
24122412
p.right_delim <<= oneOf(list(self._right_delim))
2413-
p.right_delim_safe <<= oneOf(list(self._right_delim - set(['}'])) + [r'\}'])
2413+
p.right_delim_safe <<= oneOf(list(self._right_delim - {'}'}) + [r'\}'])
24142414

24152415
p.genfrac <<= Group(
24162416
Suppress(Literal(r"\genfrac"))

‎lib/matplotlib/mlab.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2495,8 +2495,8 @@ def rec_join(key, r1, r2, jointype='inner', defaults=None, r1postfix='1',
24952495
def makekey(row):
24962496
return tuple([row[name] for name in key])
24972497

2498-
r1d = dict([(makekey(row), i) for i, row in enumerate(r1)])
2499-
r2d = dict([(makekey(row), i) for i, row in enumerate(r2)])
2498+
r1d = {makekey(row): i for i, row in enumerate(r1)}
2499+
r2d = {makekey(row): i for i, row in enumerate(r2)}
25002500

25012501
r1keys = set(r1d.keys())
25022502
r2keys = set(r2d.keys())

‎lib/matplotlib/patches.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ def __new__(self, stylename, **kw):
18671867

18681868
try:
18691869
_args_pair = [cs.split("=") for cs in _list[1:]]
1870-
_args = dict([(k, float(v)) for k, v in _args_pair])
1870+
_args = {k: float(v) for k, v in _args_pair}
18711871
except ValueError:
18721872
raise ValueError("Incorrect style argument : %s" % stylename)
18731873
_args.update(kw)

‎lib/matplotlib/pyplot.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1797,9 +1797,9 @@ def get_plot_commands():
17971797

17981798
import inspect
17991799

1800-
exclude = set(['colormaps', 'colors', 'connect', 'disconnect',
1801-
'get_plot_commands', 'get_current_fig_manager',
1802-
'ginput', 'plotting', 'waitforbuttonpress'])
1800+
exclude = {'colormaps', 'colors', 'connect', 'disconnect',
1801+
'get_plot_commands', 'get_current_fig_manager', 'ginput',
1802+
'plotting', 'waitforbuttonpress'}
18031803
exclude |= set(colormaps())
18041804
this_module = inspect.getmodule(get_plot_commands)
18051805

‎lib/matplotlib/rcsetup.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def func(s):
6262
return s.lower()
6363
else:
6464
return s
65-
self.valid = dict([(func(k), k) for k in valid])
65+
self.valid = {func(k): k for k in valid}
6666

6767
def __call__(self, s):
6868
if self.ignorecase:
@@ -683,9 +683,7 @@ def validate_hatch(s):
683683
"""
684684
if not isinstance(s, six.string_types):
685685
raise ValueError("Hatch pattern must be a string")
686-
unique_chars = set(s)
687-
unknown = (unique_chars -
688-
set(['\\', '/', '|', '-', '+', '*', '.', 'x', 'o', 'O']))
686+
unknown = set(s) - {'\\', '/', '|', '-', '+', '*', '.', 'x', 'o', 'O'}
689687
if unknown:
690688
raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
691689
return s

‎lib/matplotlib/style/core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636

3737

3838
# A list of rcParams that should not be applied from styles
39-
STYLE_BLACKLIST = set([
39+
STYLE_BLACKLIST = {
4040
'interactive', 'backend', 'backend.qt4', 'webagg.port',
4141
'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback',
4242
'toolbar', 'timezone', 'datapath', 'figure.max_open_warning',
43-
'savefig.directory', 'tk.window_focus', 'docstring.hardcopy'])
43+
'savefig.directory', 'tk.window_focus', 'docstring.hardcopy'}
4444

4545

4646
def _remove_blacklisted_style_params(d, warn=True):

0 commit comments

Comments
 (0)
Please sign in to comment.