10000 Make arguments to @deprecated/warn_deprecated keyword-only. by anntzer · Pull Request #12440 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Make arguments to @deprecated/warn_deprecated keyword-only. #12440

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 1 commit into from
Nov 1, 2018

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Oct 8, 2018

(except for the deprecated-since version)

In 2.2 there were quite a few deprecation warnings of the form

warn_deprecated("2.2", "name-of-the-deprecated-API")

(e.g. passing 'box-forced' to set_adjustable, or the 'fig' kwarg to
get_subplot_params).

Such warnings would just display the name of the deprecated API when
triggered, without actually including a deprecation message or the
deprecated-since version. This is because the correct call would have
been

warn_deprecated("2.2", name="name-of-the-deprecated-API")

(leaving message -- the first arg -- to None, and getting an
autogenerated message).

To avoid this, make all args to warn_deprecated and @deprecated
keyword-only (except the deprecated-since version).

There is no deprecation period on the old signature of these deprecator
functions(!) because they are clearly intended for internal use, because
handling signature changes is a bit of a pain and because deprecations
on the deprecation machinery is a bit too meta.

PR Summary

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 anntzer added this to the v3.1 milestone Oct 8, 2018
(except for the deprecated-since version)

In 2.2 there were quite a few deprecation warnings of the form
```
warn_deprecated("2.2", "name-of-the-deprecated-API")
```
(e.g. passing 'box-forced' to set_adjustable, or the 'fig' kwarg to
get_subplot_params).

Such warnings would just display the name of the deprecated API when
triggered, without actually including a deprecation message or the
deprecated-since version.  This is because the correct call would have
been
```
warn_deprecated("2.2", name="name-of-the-deprecated-API")
```
(leaving `message` -- the first arg -- to None, and getting an
autogenerated message).

To avoid this, make all args to `warn_deprecated` and `@deprecated`
keyword-only (except the deprecated-since version).

There is no deprecation period on the old signature of these deprecator
functions(!) because they are clearly intended for internal use, because
handling signature changes is a bit of a pain and because deprecations
on the deprecation machinery is a bit too meta.
@anntzer anntzer force-pushed the deprecatekwargonly branch from 9d51663 to 3f12eae Compare October 8, 2018 12:14
@dstansby
Copy link
Member
dstansby commented Oct 8, 2018

I'm confused, there don't seem to be any changes to cbook.py?

@@ -52,8 +52,8 @@ def _generate_deprecation_message(


def warn_deprecated(
since, message='', name='', alternative='', pending=False,
obj_type='attribute', addendum='', *, removal=''):
since, *, message='', name='', alternative='', pending=False,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's the relevant change

Copy link
Member
@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

To me, even since could be keyword-only. I've been confused in the beginning if it's the version this got deprecated in or if it's the version this will be removed in. Getting used to it now as I encounter it more and more, but it's not self-explanatory for new readers of the code.

@anntzer
Copy link
Contributor Author
anntzer commented Oct 8, 2018

I think that's too wordy to be worth it (that's literally all calls to deprecated/warn_deprecated), but I don't care that much either way.

@anntzer
Copy link
Contributor Author
anntzer commented Oct 17, 2018

@dstansby (pinging you as you already reviewed above) Are you OK with the changes?

@dstansby dstansby merged commit d4c1e72 into matplotlib:master Nov 1, 2018
@anntzer anntzer deleted the deprecatekwargonly branch November 1, 2018 09:47
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.

3 participants
0