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

Skip to content

Commit ea3e22d

Browse files
committed
PEP8: fix some of the PEP8 problems in new code
Not done: long lines between 80...100 Test code was auto-reformatted in pycharm with max line length 100
1 parent d3331ca commit ea3e22d

File tree

3 files changed

+188
-114
lines changed

3 files changed

+188
-114
lines changed

lib/matplotlib/__init__.py

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,8 +1534,8 @@ def _replacer(data, key):
15341534
return key
15351535

15361536

1537-
def unpack_labeled_data(replace_names=None, replace_all_args=False, label_namer=None,
1538-
positional_parameter_names=None):
1537+
def unpack_labeled_data(replace_names=None, replace_all_args=False,
1538+
label_namer=None, positional_parameter_names=None):
15391539
"""
15401540
A decorator to add a 'data' kwarg to any a function. The signature
15411541
of the input function must include the ax argument at the first position ::
@@ -1547,19 +1547,24 @@ def foo(ax, *args, **kwargs)
15471547
Parameters
15481548
----------
15491549
replace_names : list of strings, optional, default: None
1550-
The list of parameter names which arguments should be replaced by `data[name]`. If None,
1551-
all arguments are replaced if they are included in `data`.
1550+
The list of parameter names which arguments should be replaced by
1551+
`data[name]`. If None, all arguments are replaced if they are
1552+
included in `data`.
15521553
replace_all_args : bool, default: False
1553-
If True, all arguments in *args get replaced, even if they are not in replace_names.
1554-
NOTE: this should be used only when the order of the names depends on the number of *args.
1554+
If True, all arguments in *args get replaced, even if they are not
1555+
in replace_names.
1556+
NOTE: this should be used only when the order of the names depends on
1557+
the number of *args.
15551558
label_namer : string, optional, default: None
1556-
The name of the parameter which argument should be used as label, if label is not set. If
1557-
None, the label keyword argument is not set.
1559+
The name of the parameter which argument should be used as label, if
1560+
label is not set. If None, the label keyword argument is not set.
15581561
positional_parameter_names : list of strings, optional, default: None
1559-
The full list of positional parameter names (excluding an explicit `ax`/'self' argument at
1560-
the first place and including all possible positional parameter in `*args`), in the right
1561-
order. Can also include all other keyword parameter. Only needed if the wrapped function
1562-
does contain `*args` and (replace_names is not None or replace_all_args is False).
1562+
The full list of positional parameter names (excluding an explicit
1563+
`ax`/'self' argument at the first place and including all possible
1564+
positional parameter in `*args`), in the right order. Can also include
1565+
all other keyword parameter. Only needed if the wrapped function does
1566+
contain `*args` and (replace_names is not None or replace_all_args is
1567+
False).
15631568
"""
15641569
if replace_names is not None:
15651570
replace_names = set(replace_names)
@@ -1570,10 +1575,11 @@ def param(func):
15701575
arg_spec = inspect.getargspec(func)
15711576
_arg_names = arg_spec.args
15721577
_has_no_varargs = arg_spec.varargs is None
1573-
_has_varkwargs = not arg_spec.keywords is None
1578+
_has_varkwargs = arg_spec.keywords is not None
15741579

1575-
# there can't be any positional arguments behind *args and no positional args can end up
1576-
# in **kwargs, so we only need to check for varargs:
1580+
# there can't be any positional arguments behind *args and no
1581+
# positional args can end up in **kwargs, so we only need to check for
1582+
# varargs:
15771583
# http://stupidpythonideas.blogspot.de/2013/08/arguments-and-parameters.html
15781584
if _has_no_varargs:
15791585
# remove the first "ax" / self arg
@@ -1597,32 +1603,36 @@ def param(func):
15971603
"need 'positional_parameter_names'!"
15981604
raise AssertionError(msg % func.__name__)
15991605
else:
1600-
if not positional_parameter_names is None:
1606+
if positional_parameter_names is not None:
16011607
arg_names = positional_parameter_names
16021608
else:
16031609
if replace_all_args:
1604-
arg_names=[]
1610+
arg_names = []
16051611
else:
1606-
msg = "Got 'replace_names' and wrapped function '%s' uses *args, need 'positional_parameter_names' or 'replace_all_args'!"
1612+
msg = "Got 'replace_names' and wrapped function '%s' uses *args, " \
1613+
"need 'positional_parameter_names' or 'replace_all_args'!"
16071614
raise AssertionError(msg % func.__name__)
16081615

16091616
# compute the possible label_namer and label position in positional arguments
1610-
label_pos = 9999 # bigger than all "possible" argument lists
1611-
label_namer_pos = 9999 # bigger than all "possible" argument lists
1617+
label_pos = 9999 # bigger than all "possible" argument lists
1618+
label_namer_pos = 9999 # bigger than all "possible" argument lists
16121619
if label_namer and arg_names and (label_namer in arg_names):
16131620
label_namer_pos = arg_names.index(label_namer)
16141621
if "label" in arg_names:
16151622
label_pos = arg_names.index("label")
16161623

1617-
# Check the case we know a label_namer but we can't find it the arg_names...
1618-
# Unfortunately the label_namer can be in **kwargs, which we can't detect here and which
1619-
# results in a non-set label which might surprise the user :-(
1624+
# Check the case we know a label_namer but we can't find it the
1625+
# arg_names... Unfortunately the label_namer can be in **kwargs,
1626+
# which we can't detect here and which results in a non-set label
1627+
# which might surprise the user :-(
16201628
if label_namer and not _has_varkwargs:
16211629
if not arg_names:
1622-
msg = "label_namer '%s' can't be found as the parameter without 'positional_parameter_names'."
1623-
raise AssertionError(msg % (label_namer))
1630+
msg = "label_namer '%s' can't be found as the parameter without " \
1631+
"'positional_parameter_names'."
1632+
raise AssertionError(msg % label_namer)
16241633
elif label_namer not in arg_names:
1625-
msg = "label_namer '%s' can't be found in the parameter names (known argnames: %s)."
1634+
msg = "label_namer '%s' can't be found in the parameter names " \
1635+
"(known argnames: %s)."
16261636
raise AssertionError(msg % (label_namer, arg_names))
16271637
else:
16281638
# this is the case when the name is in arg_names
@@ -1662,8 +1672,8 @@ def inner(ax, *args, **kwargs):
16621672
# replace the label if this func "wants" a label arg and the user didn't set one
16631673
# Note: if the usere puts in "label=None", it does *NOT* get replaced!
16641674
user_supplied_label = (
1665-
(len(args) >= label_pos) or # label is included in args
1666-
('label' in kwargs) # ... or in kwargs
1675+
(len(args) >= label_pos) or # label is included in args
1676+
('label' in kwargs) # ... or in kwargs
16671677
)
16681678
if (label_namer and not user_supplied_label):
16691679
if label_namer_pos < len(args):
@@ -1678,10 +1688,13 @@ def inner(ax, *args, **kwargs):
16781688
kwargs['label'] = label
16791689
else:
16801690
import warnings
1681-
msg = "Tried to set a label via parameter '%s' in func '%s' but couldn't find such an argument. \n"\
1682-
"(This is a programming error, please report to the matplotlib list!)"
1683-
warnings.warn(msg % (label_namer, func.__name__), RuntimeWarning, stacklevel=2)
1684-
#raise Exception()
1691+
msg = "Tried to set a label via parameter '%s' in " \
1692+
"func '%s' but couldn't find such an argument. \n"\
1693+
"(This is a programming error, please report to the " \
1694+
"matplotlib list!)"
1695+
warnings.warn(msg % (label_namer, func.__name__),
1696+
RuntimeWarning, stacklevel=2)
1697+
# raise Exception()
16851698
return func(ax, *args, **kwargs)
16861699
return inner
16871700
return param

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,7 +2612,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
26122612
else:
26132613
return slices, texts, autotexts
26142614

2615-
@unpack_labeled_data(replace_names=["x", "y", "xerr", "yerr",], label_namer="y")
2615+
@unpack_labeled_data(replace_names=["x", "y", "xerr", "yerr"], label_namer="y")
26162616
@docstring.dedent_interpd
26172617
def errorbar(self, x, y, yerr=None, xerr=None,
26182618
fmt='', ecolor=None, elinewidth=None, capsize=None,
@@ -3661,7 +3661,7 @@ def dopatch(xs, ys, **kwargs):
36613661
medians=medians, fliers=fliers, means=means)
36623662

36633663
@unpack_labeled_data(replace_names=["x", "y", "s", "c", "linewidths", "edgecolors",
3664-
'facecolor', 'facecolors', 'color'], # alias for c
3664+
'facecolor', 'facecolors', 'color'], # alias for c
36653665
label_namer="y")
36663666
@docstring.dedent_interpd
36673667
def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
@@ -6172,7 +6172,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
61726172
else:
61736173
return n, bins, cbook.silent_list('Lists of Patches', patches)
61746174

6175-
@unpack_labeled_data(replace_names=["x","y", "weights"], label_namer=None)
6175+
@unpack_labeled_data(replace_names=["x", "y", "weights"], label_namer=None)
61766176
@docstring.dedent_interpd
61776177
def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
61786178
cmin=None, cmax=None, **kwargs):
@@ -6759,7 +6759,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
67596759

67606760
return spec, freqs, lines[0]
67616761

6762-
@unpack_labeled_data(replace_names=["x","y"], label_namer=None)
6762+
@unpack_labeled_data(replace_names=["x", "y"], label_namer=None)
67636763
@docstring.dedent_interpd
67646764
def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
67656765
window=mlab.window_hanning, noverlap=0, pad_to=None,
@@ -7145,7 +7145,7 @@ def matshow(self, Z, **kwargs):
71457145
integer=True))
71467146
return im
71477147

7148-
@unpack_labeled_data( replace_all_args=True, label_namer=None)
7148+
@unpack_labeled_data(replace_all_args=True, label_namer=None)
71497149
def violinplot(self, dataset, positions=None, vert=True, widths=0.5,
71507150
showmeans=False, showextrema=True, showmedians=False,
71517151
points=100, bw_method=None):

0 commit comments

Comments
 (0)