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

Skip to content

Remove unnecessary str calls. #11402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def compare_versions(a, b):


if not hasattr(sys, 'argv'): # for modpython
sys.argv = [str('modpython')]
sys.argv = ['modpython']


def _is_writable_dir(p):
Expand Down Expand Up @@ -419,7 +419,7 @@ def wrapper(*args, **kwargs):

def checkdep_dvipng():
try:
s = subprocess.Popen([str('dvipng'), '-version'],
s = subprocess.Popen(['dvipng', '-version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = s.communicate()
Expand Down Expand Up @@ -456,7 +456,7 @@ def checkdep_ghostscript():

def checkdep_pdftops():
try:
s = subprocess.Popen([str('pdftops'), '-v'], stdout=subprocess.PIPE,
s = subprocess.Popen(['pdftops', '-v'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = s.communicate()
lines = stderr.decode('ascii').split('\n')
Expand All @@ -471,7 +471,7 @@ def checkdep_pdftops():
def checkdep_inkscape():
if checkdep_inkscape.version is None:
try:
s = subprocess.Popen([str('inkscape'), '-V'],
s = subprocess.Popen(['inkscape', '-V'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = s.communicate()
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,9 +1285,9 @@ def writeGouraudTriangles(self):

streamarr = np.empty(
(shape[0] * shape[1],),
dtype=[(str('flags'), str('u1')),
(str('points'), str('>u4'), (2,)),
(str('colors'), str('u1'), (3,))])
dtype=[('flags', 'u1'),
('points', '>u4', (2,)),
('colors', 'u1', (3,))])
streamarr['flags'] = 0
streamarr['points'] = (flat_points - points_min) * factor
streamarr['colors'] = flat_colors[:, :3] * 255.0
Expand Down
9 changes: 4 additions & 5 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,8 +1409,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
latexfile = latexfile.replace("\\", "/")
# Replace ~ so Latex does not think it is line break
latexfile = latexfile.replace("~", "\\string~")
command = [str("latex"), "-interaction=nonstopmode",
'"%s"' % latexfile]
command = ["latex", "-interaction=nonstopmode", '"%s"' % latexfile]
_log.debug('%s', command)
try:
report = subprocess.check_output(command, cwd=tmpdir,
Expand All @@ -1424,7 +1423,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
exc.output.decode("utf-8"))))
_log.debug(report)

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

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

command = [str("pdftops"), "-paper", "match", "-level2", pdffile, psfile]
command = ["pdftops", "-paper", "match", "-level2", pdffile, psfile]
_log.debug(command)
try:
report = subprocess.check_output(command, stderr=subprocess.STDOUT)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def utcoffset(self, dt):
return datetime.timedelta(0)

def tzname(self, dt):
return str("UTC")
return "UTC"

def dst(self, dt):
return datetime.timedelta(0)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def setup(app):
app.add_config_value('plot_working_directory', None, True)
app.add_config_value('plot_template', None, True)

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

metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata
Expand Down
18 changes: 6 additions & 12 deletions lib/matplotlib/tests/test_mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ def tempcsv():


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


def test_rec2csv_bad_shape_ValueError(tempcsv):
bad = np.recarray((99, 4), [(str('x'), float),
(str('y'), float)])
bad = np.recarray((99, 4), [('x', float), ('y', float)])

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


def test_rec2txt_basic():
# str() calls around field names necessary b/c as of numpy 1.11
# dtype doesn't like unicode names (caused by unicode_literals import)
a = np.array([(1.0, 2, 'foo', 'bing'),
(2.0, 3, 'bar', 'blah')],
dtype=np.dtype([(str('x'), np.float32),
(str('y'), np.int8),
(str('s'), str, 3),
(str('s2'), str, 4)]))
dtype=np.dtype([('x', np.float32),
('y', np.int8),
('s', str, 3),
('s2', str, 4)]))
truth = (' x y s s2\n'
' 1.000 2 foo bing \n'
' 2.000 3 bar blah ').splitlines()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/type1font.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _read(self, file):
'got %d)' % rawdata[0])
type = rawdata[1]
if type in (1, 2):
length, = struct.unpack(str('<i'), rawdata[2:6])
length, = struct.unpack('<i', rawdata[2:6])
segment = rawdata[6:6 + length]
rawdata = rawdata[6 + length:]

Expand Down
26 changes: 7 additions & 19 deletions lib/mpl_toolkits/axes_grid1/axes_divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
and vertical lists of sizes that the division will be based on. You
then use the new_locator method, whose return value is a callable
object that can be used to set the axes_locator of the axes.

"""
import matplotlib.transforms as mtransforms

from matplotlib.axes import SubplotBase
import functools

import matplotlib.transforms as mtransforms
from matplotlib.axes import SubplotBase
from . import axes_size as Size


Expand Down Expand Up @@ -906,24 +906,12 @@ def _make_twin_axes(self, *kl, **kwargs):
self._twinned_axes.join(self, ax2)
return ax2

_locatableaxes_classes = {}


@functools.lru_cache(None)
def locatable_axes_factory(axes_class):

new_class = _locatableaxes_classes.get(axes_class)
if new_class is None:
new_class = type(str("Locatable%s" % (axes_class.__name__)),
(LocatableAxesBase, axes_class),
{'_axes_class': axes_class})

_locatableaxes_classes[axes_class] = new_class

return new_class

#if hasattr(maxes.Axes, "get_axes_locator"):
# LocatableAxes = maxes.Axes
#else:
return type("Locatable%s" % axes_class.__name__,
(LocatableAxesBase, axes_class),
{'_axes_class': axes_class})


def make_axes_locatable(axes):
Expand Down