Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ec0b049

Browse filesBrowse files
authored
Merge pull request #11402 from anntzer/strcalls
MNT: Remove unnecessary str calls.
2 parents cd1ae80 + a9e5400 commit ec0b049
Copy full SHA for ec0b049

File tree

Expand file treeCollapse file tree

8 files changed

+27
-46
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+27
-46
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def compare_versions(a, b):
213213

214214

215215
if not hasattr(sys, 'argv'): # for modpython
216-
sys.argv = [str('modpython')]
216+
sys.argv = ['modpython']
217217

218218

219219
def _is_writable_dir(p):
@@ -419,7 +419,7 @@ def wrapper(*args, **kwargs):
419419

420420
def checkdep_dvipng():
421421
try:
422-
s = subprocess.Popen([str('dvipng'), '-version'],
422+
s = subprocess.Popen(['dvipng', '-version'],
423423
stdout=subprocess.PIPE,
424424
stderr=subprocess.PIPE)
425425
stdout, stderr = s.communicate()
@@ -456,7 +456,7 @@ def checkdep_ghostscript():
456456

457457
def checkdep_pdftops():
458458
try:
459-
s = subprocess.Popen([str('pdftops'), '-v'], stdout=subprocess.PIPE,
459+
s = subprocess.Popen(['pdftops', '-v'], stdout=subprocess.PIPE,
460460
stderr=subprocess.PIPE)
461461
stdout, stderr = s.communicate()
462462
lines = stderr.decode('ascii').split('\n')
@@ -471,7 +471,7 @@ def checkdep_pdftops():
471471
def checkdep_inkscape():
472472
if checkdep_inkscape.version is None:
473473
try:
474-
s = subprocess.Popen([str('inkscape'), '-V'],
474+
s = subprocess.Popen(['inkscape', '-V'],
475475
stdout=subprocess.PIPE,
476476
stderr=subprocess.PIPE)
477477
stdout, stderr = s.communicate()

‎lib/matplotlib/backends/backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pdf.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,9 @@ def writeGouraudTriangles(self):
12851285

12861286
streamarr = np.empty(
12871287
(shape[0] * shape[1],),
1288-
dtype=[(str('flags'), str('u1')),
1289-
(str('points'), str('>u4'), (2,)),
1290-
(str('colors'), str('u1'), (3,))])
1288+
dtype=[('flags', 'u1'),
1289+
('points', '>u4', (2,)),
1290+
('colors', 'u1', (3,))])
12911291
streamarr['flags'] = 0
12921292
streamarr['points'] = (flat_points - points_min) * factor
12931293
streamarr['colors'] = flat_colors[:, :3] * 255.0

‎lib/matplotlib/backends/backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,8 +1409,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
14091409
latexfile = latexfile.replace("\\", "/")
14101410
# Replace ~ so Latex does not think it is line break
14111411
latexfile = latexfile.replace("~", "\\string~")
1412-
command = [str("latex"), "-interaction=nonstopmode",
1413-
'"%s"' % latexfile]
1412+
command = ["latex", "-interaction=nonstopmode", '"%s"' % latexfile]
14141413
_log.debug('%s', command)
14151414
try:
14161415
report = subprocess.check_output(command, cwd=tmpdir,
@@ -1424,7 +1423,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
14241423
exc.output.decode("utf-8"))))
14251424
_log.debug(report)
14261425

1427-
command = [str('dvips'), '-q', '-R0', '-o', os.path.basename(psfile),
1426+
command = ['dvips', '-q', '-R0', '-o', os.path.basename(psfile),
14281427
os.path.basename(dvifile)]
14291428
_log.debug(command)
14301429
try:
@@ -1525,7 +1524,7 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15251524

15261525
# Pass options as `-foo#bar` instead of `-foo=bar` to keep Windows happy
15271526
# (https://www.ghostscript.com/doc/9.22/Use.htm#MS_Windows).
1528-
command = [str("ps2pdf"),
1527+
command = ["ps2pdf",
15291528
"-dAutoFilterColorImages#false",
15301529
"-dAutoFilterGrayImages#false",
15311530
"-dAutoRotatePages#false",
@@ -1544,7 +1543,7 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15441543
'\n\n' % exc.output.decode("utf-8")))
15451544
_log.debug(report)
15461545

1547-
command = [str("pdftops"), "-paper", "match", "-level2", pdffile, psfile]
1546+
command = ["pdftops", "-paper", "match", "-level2", pdffile, psfile]
15481547
_log.debug(command)
15491548
try:
15501549
report = subprocess.check_output(command, stderr=subprocess.STDOUT)

‎lib/matplotlib/dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dates.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def utcoffset(self, dt):
185185
return datetime.timedelta(0)
186186

187187
def tzname(self, dt):
188-
return str("UTC")
188+
return "UTC"
189189

190190
def dst(self, dt):
191191
return datetime.timedelta(0)

‎lib/matplotlib/sphinxext/plot_directive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sphinxext/plot_directive.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def setup(app):
276276
app.add_config_value('plot_working_directory', None, True)
277277
app.add_config_value('plot_template', None, True)
278278

279-
app.connect(str('doctree-read'), mark_plot_labels)
279+
app.connect('doctree-read', mark_plot_labels)
280280

281281
metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
282282
return metadata

‎lib/matplotlib/tests/test_mlab.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_mlab.py
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ def tempcsv():
213213

214214

215215
def test_recarray_csv_roundtrip(tempcsv):
216-
expected = np.recarray((99,),
217-
[(str('x'), float),
218-
(str('y'), float),
219-
(str('t'), float)])
216+
expected = np.recarray((99,), [('x', float), ('y', float), ('t', float)])
220217
# initialising all values: uninitialised memory sometimes produces
221218
# floats that do not round-trip to string and back.
222219
expected['x'][:] = np.linspace(-1e9, -1, 99)
@@ -233,8 +230,7 @@ def test_recarray_csv_roundtrip(tempcsv):
233230

234231

235232
def test_rec2csv_bad_shape_ValueError(tempcsv):
236-
bad = np.recarray((99, 4), [(str('x'), float),
237-
(str('y'), float)])
233+
bad = np.recarray((99, 4), [('x', float), ('y', float)])
238234

239235
# the bad recarray should trigger a ValueError for having ndim > 1.
240236
with pytest.warns(MatplotlibDeprecationWarning):
@@ -286,14 +282,12 @@ def test_csv2rec_dates(tempcsv, input, kwargs):
286282

287283

288284
def test_rec2txt_basic():
289-
# str() calls around field names necessary b/c as of numpy 1.11
290-
# dtype doesn't like unicode names (caused by unicode_literals import)
291285
a = np.array([(1.0, 2, 'foo', 'bing'),
292286
(2.0, 3, 'bar', 'blah')],
293-
dtype=np.dtype([(str('x'), np.float32),
294-
(str('y'), np.int8),
295-
(str('s'), str, 3),
296-
(str('s2'), str, 4)]))
287+
dtype=np.dtype([('x', np.float32),
288+
('y', np.int8),
289+
('s', str, 3),
290+
('s2', str, 4)]))
297291
truth = (' x y s s2\n'
298292
' 1.000 2 foo bing \n'
299293
' 2.000 3 bar blah ').splitlines()

‎lib/matplotlib/type1font.py

Copy file name to clipboardExpand all lines: lib/matplotlib/type1font.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _read(self, file):
8181
'got %d)' % rawdata[0])
8282
type = rawdata[1]
8383
if type in (1, 2):
84-
length, = struct.unpack(str('<i'), rawdata[2:6])
84+
length, = struct.unpack('<i', rawdata[2:6])
8585
segment = rawdata[6:6 + length]
8686
rawdata = rawdata[6 + length:]
8787

‎lib/mpl_toolkits/axes_grid1/axes_divider.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/axes_divider.py
+7-19Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
and vertical lists of sizes that the division will be based on. You
99
then use the new_locator method, whose return value is a callable
1010
object that can be used to set the axes_locator of the axes.
11-
1211
"""
13-
import matplotlib.transforms as mtransforms
1412

15-
from matplotlib.axes import SubplotBase
13+
import functools
1614

15+
import matplotlib.transforms as mtransforms
16+
from matplotlib.axes import SubplotBase
1717
from . import axes_size as Size
1818

1919

@@ -906,24 +906,12 @@ def _make_twin_axes(self, *kl, **kwargs):
906906
self._twinned_axes.join(self, ax2)
907907
return ax2
908908

909-
_locatableaxes_classes = {}
910-
911909

910+
@functools.lru_cache(None)
912911
def locatable_axes_factory(axes_class):
913-
914-
new_class = _locatableaxes_classes.get(axes_class)
915-
if new_class is None:
916-
new_class = type(str("Locatable%s" % (axes_class.__name__)),
917-
(LocatableAxesBase, axes_class),
918-
{'_axes_class': axes_class})
919-
920-
_locatableaxes_classes[axes_class] = new_class
921-
922-
return new_class
923-
924-
#if hasattr(maxes.Axes, "get_axes_locator"):
925-
# LocatableAxes = maxes.Axes
926-
#else:
912+
return type("Locatable%s" % axes_class.__name__,
913+
(LocatableAxesBase, axes_class),
914+
{'_axes_class': axes_class})
927915

928916

929917
def make_axes_locatable(axes):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.