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

Skip to content

Commit 5ca32ab

Browse files
committed
Completely deprecate is_string_like.
I had missed that numpy's `str_` (and `unicode_` on Py2) derive from the corresponding builtin type(s), so `isinstance(x, six.string_types)` is just as good.
1 parent 1c0b96c commit 5ca32ab

49 files changed

Lines changed: 140 additions & 156 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
`cbook.is_numlike` and `cbook.is_string_like` only perform an instance check
2-
````````````````````````````````````````````````````````````````````````````
1+
`cbook.is_numlike` only performs an instance check, `cbook.is_string_like` is deprecated
2+
````````````````````````````````````````````````````````````````````````````````````````
33

4-
`cbook.is_numlike` and `cbook.is_string_like` now only check that
5-
their argument is an instance of ``(numbers.Number, np.Number)`` and
6-
``(six.string_types, np.str_, np.unicode_)`` respectively. In particular, this
7-
means that arrays are now never num-like or string-like regardless of their
8-
dtype.
4+
`cbook.is_numlike` now only checks that its argument is an instance of
5+
``(numbers.Number, np.Number)`` and. In particular, this means that arrays are
6+
now not num-like.
7+
8+
`cbook.is_string_like` and `cbook.is_sequence_of_strings` have been
9+
deprecated. Use ``isinstance(obj, six.string_types)`` and ``all(isinstance(o,
10+
six.string_types) for o in obj) and not iterable(obj)`` instead.

examples/misc/rc_traits.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import os
1111
import re
1212
import traits.api as traits
13-
from matplotlib.cbook import is_string_like
1413
from matplotlib.artist import Artist
1514

1615
doprint = True
@@ -75,7 +74,7 @@ def tuple_to_rgba(ob, name, val):
7574
def hex_to_rgba(ob, name, val):
7675
rgx = re.compile('^#[0-9A-Fa-f]{6}$')
7776

78-
if not is_string_like(val):
77+
if not isinstance(val, six.string_types):
7978
raise TypeError
8079
if rgx.match(val) is None:
8180
raise ValueError

lib/matplotlib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
# cbook must import matplotlib only within function
122122
# definitions, so it is safe to import from it here.
123123
from . import cbook
124-
from matplotlib.cbook import (is_string_like,
124+
from matplotlib.cbook import (
125125
mplDeprecation,
126126
dedent, get_label,
127127
sanitize_sequence)
@@ -1225,7 +1225,7 @@ def rc(group, **kwargs):
12251225
'aa': 'antialiased',
12261226
}
12271227

1228-
if is_string_like(group):
1228+
if isinstance(group, six.string_types):
12291229
group = (group,)
12301230
for g in group:
12311231
for k, v in six.iteritems(kwargs):

lib/matplotlib/animation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import contextlib
3939
import tempfile
4040
import warnings
41-
from matplotlib.cbook import iterable, is_string_like, deprecated
41+
from matplotlib.cbook import iterable, deprecated
4242
from matplotlib.compat import subprocess
4343
from matplotlib import verbose
4444
from matplotlib import rcParams, rcParamsDefault, rc_context
@@ -1023,7 +1023,7 @@ class to use, such as 'ffmpeg' or 'mencoder'. If `None`,
10231023
# to use
10241024
if writer is None:
10251025
writer = rcParams['animation.writer']
1026-
elif (not is_string_like(writer) and
1026+
elif (not isinstance(writer, six.string_types) and
10271027
any(arg is not None
10281028
for arg in (fps, codec, bitrate, extra_args, metadata))):
10291029
raise RuntimeError('Passing in values for arguments '
@@ -1068,7 +1068,7 @@ class to use, such as 'ffmpeg' or 'mencoder'. If `None`,
10681068

10691069
# If we have the name of a writer, instantiate an instance of the
10701070
# registered class.
1071-
if is_string_like(writer):
1071+
if isinstance(writer, six.string_types):
10721072
if writer in writers.avail:
10731073
writer = writers[writer](fps, codec, bitrate,
10741074
extra_args=extra_args,

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import matplotlib.cbook as cbook
1919
from matplotlib.cbook import (mplDeprecation, STEP_LOOKUP_MAP,
20-
iterable, is_string_like,
20+
iterable,
2121
safe_first_element)
2222
import matplotlib.collections as mcoll
2323
import matplotlib.colors as mcolors
@@ -2662,7 +2662,7 @@ def get_next_color():
26622662
if autopct is not None:
26632663
xt = x + pctdistance * radius * math.cos(thetam)
26642664
yt = y + pctdistance * radius * math.sin(thetam)
2665-
if is_string_like(autopct):
2665+
if isinstance(autopct, six.string_types):
26662666
s = autopct % (100. * frac)
26672667
elif callable(autopct):
26682668
s = autopct(100. * frac)
@@ -5472,8 +5472,8 @@ def pcolor(self, *args, **kwargs):
54725472
# makes artifacts that are often disturbing.
54735473
if 'antialiased' in kwargs:
54745474
kwargs['antialiaseds'] = kwargs.pop('antialiased')
5475-
if 'antialiaseds' not in kwargs and (is_string_like(ec) and
5476-
ec.lower() == "none"):
5475+
if 'antialiaseds' not in kwargs and (
5476+
isinstance(ec, six.string_types) and ec.lower() == "none"):
54775477
kwargs['antialiaseds'] = False
54785478

54795479
kwargs.setdefault('snap', False)
@@ -6380,7 +6380,7 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
63806380

63816381
if label is None:
63826382
labels = [None]
6383-
elif is_string_like(label):
6383+
elif isinstance(label, six.string_types):
63846384
labels = [label]
63856385
else:
63866386
labels = [six.text_type(lab) for lab in label]

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def _makefill(self, x, y, kw, kwargs):
352352

353353
def _plot_args(self, tup, kwargs):
354354
ret = []
355-
if len(tup) > 1 and is_string_like(tup[-1]):
355+
if len(tup) > 1 and isinstance(tup[-1], six.string_types):
356356
linestyle, marker, color = _process_plot_format(tup[-1])
357357
tup = tup[:-1]
358358
elif len(tup) == 3:
@@ -398,7 +398,7 @@ def _plot_args(self, tup, kwargs):
398398
def _grab_next_args(self, *args, **kwargs):
399399
while args:
400400
this, args = args[:2], args[2:]
401-
if args and is_string_like(args[0]):
401+
if args and isinstance(args[0], six.string_types):
402402
this += args[0],
403403
args = args[1:]
404404
for seg in self._plot_args(this, kwargs):
@@ -1281,7 +1281,7 @@ def set_aspect(self, aspect, adjustable=None, anchor=None):
12811281
etc.
12821282
===== =====================
12831283
"""
1284-
if cbook.is_string_like(aspect) and aspect in ('equal', 'auto'):
1284+
if isinstance(aspect, six.string_types) and aspect in ('equal', 'auto'):
12851285
self._aspect = aspect
12861286
else:
12871287
self._aspect = float(aspect) # raise ValueError if necessary
@@ -1556,7 +1556,7 @@ def axis(self, *v, **kwargs):
15561556

15571557
emit = kwargs.get('emit', True)
15581558

1559-
if len(v) == 1 and is_string_like(v[0]):
1559+
if len(v) == 1 and isinstance(v[0], six.string_types):
15601560
s = v[0].lower()
15611561
if s == 'on':
15621562
self.set_axis_on()

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def get_registered_canvas_class(format):
129129
if format not in _default_backends:
130130
return None
131131
backend_class = _default_backends[format]
132-
if cbook.is_string_like(backend_class):
132+
if isinstance(backend_class, six.string_types):
133133
backend_class = importlib.import_module(backend_class).FigureCanvas
134134
_default_backends[format] = backend_class
135135
return backend_class
@@ -2090,11 +2090,11 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
20902090

20912091
if format is None:
20922092
# get format from filename, or from backend's default filetype
2093-
if cbook.is_string_like(filename):
2093+
if isinstance(filename, six.string_types):
20942094
format = os.path.splitext(filename)[1][1:]
20952095
if format is None or format == '':
20962096
format = self.get_default_filetype()
2097-
if cbook.is_string_like(filename):
2097+
if isinstance(filename, six.string_types):
20982098
filename = filename.rstrip('.') + '.' + format
20992099
format = format.lower()
21002100

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from matplotlib import verbose, rcParams, __version__
3232
from matplotlib.backend_bases import (RendererBase, FigureManagerBase,
3333
FigureCanvasBase)
34-
from matplotlib.cbook import is_string_like, maxdict, restrict_dict
34+
from matplotlib.cbook import maxdict, restrict_dict
3535
from matplotlib.figure import Figure
3636
from matplotlib.font_manager import findfont, get_font
3737
from matplotlib.ft2font import (LOAD_FORCE_AUTOHINT, LOAD_NO_HINTING,
@@ -530,7 +530,7 @@ def print_raw(self, filename_or_obj, *args, **kwargs):
530530
renderer = self.get_renderer()
531531
original_dpi = renderer.dpi
532532
renderer.dpi = self.figure.dpi
533-
if is_string_like(filename_or_obj):
533+
if isinstance(filename_or_obj, six.string_types):
534534
fileobj = open(filename_or_obj, 'wb')
535535
close = True
536536
else:
@@ -549,7 +549,7 @@ def print_png(self, filename_or_obj, *args, **kwargs):
549549
renderer = self.get_renderer()
550550
original_dpi = renderer.dpi
551551
renderer.dpi = self.figure.dpi
552-
if is_string_like(filename_or_obj):
552+
if isinstance(filename_or_obj, six.string_types):
553553
filename_or_obj = open(filename_or_obj, 'wb')
554554
close = True
555555
else:

lib/matplotlib/backends/backend_cairo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
5151

5252
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
5353
FigureManagerBase, FigureCanvasBase
54-
from matplotlib.cbook import is_string_like
5554
from matplotlib.figure import Figure
5655
from matplotlib.mathtext import MathTextParser
5756
from matplotlib.path import Path
@@ -555,7 +554,7 @@ def _save (self, fo, format, **kwargs):
555554
raise RuntimeError ('cairo has not been compiled with SVG '
556555
'support enabled')
557556
if format == 'svgz':
558-
if is_string_like(fo):
557+
if isinstance(fo, six.string_types):
559558
fo = gzip.GzipFile(fo, 'wb')
560559
else:
561560
fo = gzip.GzipFile(None, 'wb', fileobj=fo)

lib/matplotlib/backends/backend_gdk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
2626
from matplotlib._pylab_helpers import Gcf
2727
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
2828
FigureManagerBase, FigureCanvasBase
29-
from matplotlib.cbook import is_string_like, restrict_dict, warn_deprecated
29+
from matplotlib.cbook import restrict_dict, warn_deprecated
3030
from matplotlib.figure import Figure
3131
from matplotlib.mathtext import MathTextParser
3232
from matplotlib.transforms import Affine2D

0 commit comments

Comments
 (0)