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

Skip to content

Commit cdb830d

Browse files
committed
Don't go via six for callable(); related cleanups.
1 parent de5a4ee commit cdb830d

20 files changed

Lines changed: 55 additions & 73 deletions

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def wrap(self, fmt, func, level='helpful', always=True):
333333
if always is True, the report will occur on every function
334334
call; otherwise only on the first time the function is called
335335
"""
336-
assert six.callable(func)
336+
assert callable(func)
337337

338338
def wrapper(*args, **kwargs):
339339
ret = func(*args, **kwargs)

lib/matplotlib/animation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,14 +1290,14 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
12901290
# will be treated as a number of frames.
12911291
if frames is None:
12921292
self._iter_gen = itertools.count
1293-
elif six.callable(frames):
1293+
elif callable(frames):
12941294
self._iter_gen = frames
12951295
elif iterable(frames):
12961296
self._iter_gen = lambda: iter(frames)
12971297
if hasattr(frames, '__len__'):
12981298
self.save_count = len(frames)
12991299
else:
1300-
self._iter_gen = lambda: xrange(frames).__iter__()
1300+
self._iter_gen = lambda: iter(xrange(frames))
13011301
self.save_count = frames
13021302

13031303
# If we're passed in and using the default, set it to 100.

lib/matplotlib/artist.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def contains(self, mouseevent):
392392
selection, such as which points are contained in the pick radius. See
393393
individual artists for details.
394394
"""
395-
if six.callable(self._contains):
395+
if callable(self._contains):
396396
return self._contains(self, mouseevent)
397397
warnings.warn("'%s' needs 'contains' method" % self.__class__.__name__)
398398
return False, {}
@@ -435,7 +435,7 @@ def pick(self, mouseevent):
435435
# Pick self
436436
if self.pickable():
437437
picker = self.get_picker()
438-
if six.callable(picker):
438+
if picker is not None:
439439
inside, prop = picker(self, mouseevent)
440440
else:
441441
inside, prop = self.contains(mouseevent)
@@ -446,8 +446,8 @@ def pick(self, mouseevent):
446446
for a in self.get_children():
447447
# make sure the event happened in the same axes
448448
ax = getattr(a, 'axes', None)
449-
if mouseevent.inaxes is None or ax is None or \
450-
mouseevent.inaxes == ax:
449+
if (mouseevent.inaxes is None or ax is None
450+
or mouseevent.inaxes == ax):
451451
# we need to check if mouseevent.inaxes is None
452452
# because some objects associated with an axes (e.g., a
453453
# tick label) can be outside the bounding box of the
@@ -873,7 +873,7 @@ def _update_property(self, k, v):
873873
return setattr(self, k, v)
874874
else:
875875
func = getattr(self, 'set_' + k, None)
876-
if func is None or not six.callable(func):
876+
if not callable(func):
877877
raise AttributeError('Unknown property %s' % k)
878878
return func(v)
879879

@@ -1075,7 +1075,7 @@ def matchfunc(x):
10751075
elif cbook.issubclass_safe(match, Artist):
10761076
def matchfunc(x):
10771077
return isinstance(x, match)
1078-
elif six.callable(match):
1078+
elif callable(match):
10791079
matchfunc = match
10801080
else:
10811081
raise ValueError('match must be None, a matplotlib.artist.Artist '
@@ -1166,9 +1166,9 @@ def get_aliases(self):
11661166
}
11671167
11681168
"""
1169-
names = [name for name in dir(self.o) if
1170-
(name.startswith('set_') or name.startswith('get_'))
1171-
and six.callable(getattr(self.o, name))]
1169+
names = [name for name in dir(self.o)
1170+
if name.startswith(('set_', 'get_'))
1171+
and callable(getattr(self.o, name))]
11721172
aliases = {}
11731173
for name in names:
11741174
func = getattr(self.o, name)
@@ -1222,17 +1222,14 @@ def _get_setters_and_targets(self):
12221222
for name in dir(self.o):
12231223
if not name.startswith('set_'):
12241224
continue
1225-
o = getattr(self.o, name)
1226-
if not six.callable(o):
1225+
func = getattr(self.o, name)
1226+
if not callable(func):
12271227
continue
12281228
if six.PY2:
1229-
nargs = len(inspect.getargspec(o)[0])
1229+
nargs = len(inspect.getargspec(func)[0])
12301230
else:
1231-
nargs = len(inspect.getfullargspec(o)[0])
1232-
if nargs < 2:
1233-
continue
1234-
func = o
1235-
if self.is_alias(func):
1231+
nargs = len(inspect.getfullargspec(func)[0])
1232+
if nargs < 2 or self.is_alias(func):
12361233
continue
12371234
source_class = self.o.__module__ + "." + self.o.__name__
12381235
for cls in self.o.mro():
@@ -1371,8 +1368,7 @@ def properties(self):
13711368
"""
13721369
o = self.oorig
13731370
getters = [name for name in dir(o)
1374-
if name.startswith('get_')
1375-
and six.callable(getattr(o, name))]
1371+
if name.startswith('get_') and callable(getattr(o, name))]
13761372
getters.sort()
13771373
d = dict()
13781374
for name in getters:
@@ -1432,7 +1428,7 @@ def matchfunc(x):
14321428
elif issubclass(match, Artist):
14331429
def matchfunc(x):
14341430
return isinstance(x, match)
1435-
elif six.callable(match):
1431+
elif callable(match):
14361432
matchfunc = func
14371433
else:
14381434
raise ValueError('match must be None, a matplotlib.artist.Artist '

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ def get_next_color():
26642664
yt = y + pctdistance * radius * math.sin(thetam)
26652665
if is_string_like(autopct):
26662666
s = autopct % (100. * frac)
2667-
elif six.callable(autopct):
2667+
elif callable(autopct):
26682668
s = autopct(100. * frac)
26692669
else:
26702670
raise TypeError(

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,9 +3807,8 @@ def contains(self, mouseevent):
38073807
38083808
Returns *True* / *False*, {}
38093809
"""
3810-
if six.callable(self._contains):
3810+
if callable(self._contains):
38113811
return self._contains(self, mouseevent)
3812-
38133812
return self.patch.contains(mouseevent)
38143813

38153814
def contains_point(self, point):

lib/matplotlib/axis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def contains(self, mouseevent):
209209
This function always returns false. It is more useful to test if the
210210
axis as a whole contains the mouse rather than the set of tick marks.
211211
"""
212-
if six.callable(self._contains):
212+
if callable(self._contains):
213213
return self._contains(self, mouseevent)
214214
return False, {}
215215

@@ -1712,7 +1712,7 @@ class XAxis(Axis):
17121712
def contains(self, mouseevent):
17131713
"""Test whether the mouse event occured in the x axis.
17141714
"""
1715-
if six.callable(self._contains):
1715+
if callable(self._contains):
17161716
return self._contains(self, mouseevent)
17171717

17181718
x, y = mouseevent.x, mouseevent.y
@@ -2040,7 +2040,7 @@ def contains(self, mouseevent):
20402040
20412041
Returns *True* | *False*
20422042
"""
2043-
if six.callable(self._contains):
2043+
if callable(self._contains):
20442044
return self._contains(self, mouseevent)
20452045

20462046
x, y = mouseevent.x, mouseevent.y

lib/matplotlib/cbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ def is_hashable(obj):
715715

716716
def is_writable_file_like(obj):
717717
"""return true if *obj* looks like a file object with a *write* method"""
718-
return hasattr(obj, 'write') and six.callable(obj.write)
718+
return callable(getattr(obj, 'write', None))
719719

720720

721721
def file_requires_unicode(x):

lib/matplotlib/cm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def revcmap(data):
3636
"""Can only handle specification *data* in dictionary format."""
3737
data_r = {}
3838
for key, val in six.iteritems(data):
39-
if six.callable(val):
39+
if callable(val):
4040
valnew = _reverser(val)
4141
# This doesn't work: lambda x: val(1-x)
4242
# The same "val" (the first one) is used

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def contains(self, mouseevent):
360360
Returns True | False, ``dict(ind=itemlist)``, where every
361361
item in itemlist contains the event.
362362
"""
363-
if six.callable(self._contains):
363+
if callable(self._contains):
364364
return self._contains(self, mouseevent)
365365

366366
if not self.get_visible():

lib/matplotlib/colors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def makeMappingArray(N, data, gamma=1.0):
351351
gives the closest value for values of x between 0 and 1.
352352
"""
353353

354-
if six.callable(data):
354+
if callable(data):
355355
xind = np.linspace(0, 1, N) ** gamma
356356
lut = np.clip(np.array(data(xind), dtype=float), 0, 1)
357357
return lut
@@ -733,7 +733,7 @@ def func_r(x):
733733

734734
data_r = dict()
735735
for key, data in six.iteritems(self._segmentdata):
736-
if six.callable(data):
736+
if callable(data):
737737
data_r[key] = factory(data)
738738
else:
739739
new_data = [(1.0 - x, y1, y0) for x, y0, y1 in reversed(data)]

0 commit comments

Comments
 (0)