Fix edge-case in preprocess_data, if label_namer is optional and unset. #16613
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
First commit (the important one):
9728144 removed a call to
BoundArguments.apply_defaults
to guardagainst an API change in Py3.9. As it turns out this means that
all_kwargs[label_namer]
can now fail, in theory, if _preprocess_datais 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).(TL;DR: 9728144 broke _preprocess_data in an edge case that isn't
exercised anywhere in mpl; it's private API so in theory no one else
should be exercising that edge case but let's still fix it.)
Second commit (just a simplification):
We don't need to evaluate needs_label at the top, we can just do it when
needed. Also rename all_kwargs to args_and_kwargs, as it's really a
mapping of all arg names to their values, whether they have been passed
positionally or by keyword.
PR Checklist