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

Skip to content

Commit e445831

Browse files
committed
Fix edge-case in preprocess_data, if label_namer is optional and unset.
9728144 removed a call to `BoundArguments.apply_defaults` to guard against an API change in Py3.9. As it turns out this means that `all_kwargs[label_namer]` can now fail, in theory, if _preprocess_data is used on a function for which label_namer is an *optional* parameter (because the default won't be set in all_kwargs). Fortunately, 1) there is no such case (it would be semantically questionable to derive the label from a non-required argument...) and 2) the fix is simple (use `all_kwargs.get` instead -- _label_namer properly handles None).
1 parent 70d59ae commit e445831

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

lib/matplotlib/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,10 +1405,8 @@ def inner(ax, *args, data=None, **kwargs):
14051405

14061406
if needs_label:
14071407
all_kwargs = {**bound.arguments, **bound.kwargs}
1408-
# label_namer will be in all_kwargs as we asserted above that
1409-
# `label_namer is None or label_namer in arg_names`.
14101408
new_kwargs["label"] = _label_from_arg(
1411-
all_kwargs[label_namer], auto_label)
1409+
all_kwargs.get(label_namer), auto_label)
14121410

14131411
return func(*new_args, **new_kwargs)
14141412

0 commit comments

Comments
 (0)