Skip to content

Commit 69622dd

Browse files
committed
set/dict literals/comprehensions.
1 parent 3d00576 commit 69622dd

File tree

29 files changed

+70
-88
lines changed

29 files changed

+70
-88
lines changed

boilerplate.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 8 additions & 11 deletions
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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):

0 commit comments

Comments
 (0)