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

Skip to content

Fix edge-case in preprocess_data, if label_namer is optional and unset. #16613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 1, 2020

PR Summary

First commit (the important one):

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).

(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

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

anntzer added 2 commits March 1, 2020 11:51
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).
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.
@anntzer anntzer added this to the v3.2.1 milestone Mar 1, 2020
Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should maybe get a test since it's fixing a bug that we don't test for yet?

@anntzer
Copy link
Contributor Author

anntzer commented Mar 1, 2020

As argued above, I don't think the failing case makes sense semantically anyways...

@timhoffm timhoffm merged commit a6bd231 into matplotlib:master Mar 1, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 1, 2020
@anntzer anntzer deleted the ppd branch March 1, 2020 21:20
timhoffm added a commit that referenced this pull request Mar 1, 2020
…613-on-v3.2.x

Backport PR #16613 on branch v3.2.x (Fix edge-case in preprocess_data, if label_namer is optional and unset.)
@tacaswell tacaswell modified the milestones: v3.2.1, v3.2.0 Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants