Skip to content

Don't pretend @deprecated applies to classmethods. #12151

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
Sep 21, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 18, 2018

The @deprecated decorator has a branch for handling deprecation of
classmethods, but that won't ever work because we start by getting
the __name__ attribute on the object, which raises an AttributeError
on classmethods.

This could be fixed by fetching obj.__func__.__name__ instead, but
given that one can as well put the @deprecated decorator under the
@classmethod decorator (so that it sees the underlying function), we
can just remove that non-functioning code.

Also switch some docstring formatting to str.format.

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 Sep 18, 2018
new_doc = (('\n.. deprecated:: %(since)s'
'\n %(message)s\n\n' %
{'since': since, 'message': message}) + old_doc)
new_doc = ('.. deprecated:: {}\n'
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather keep named placeholders, i.e. {since}.

When do we require Python 3.6 so that we can use f-strings? 😏 So long, I'd take the .format(since=since, ...) workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

The `@deprecated` decorator has a branch for handling deprecation of
classmethods, but that won't ever work because we start by getting
the `__name__` attribute on the object, which raises an AttributeError
on classmethods.

This could be fixed by fetching `obj.__func__.__name__` instead, but
given that one can as well put the `@deprecated` decorator *under* the
`@classmethod` decorator (so that it sees the underlying function), we
can just remove that non-functioning code.

Also switch some docstring formatting to str.format.
@anntzer anntzer force-pushed the classmethod-deprecation branch from 8abe9f6 to 167ede8 Compare September 18, 2018 19:40
new_doc = (('\n.. deprecated:: %(since)s'
'\n %(message)s\n\n' %
{'since': since, 'message': message}) + old_doc)
new_doc = ('.. deprecated:: {since}\n'
Copy link
Member

Choose a reason for hiding this comment

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

What happened to the leading newline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's at the beginning of the docstring so it doesn't matter.

OTOH I realized that we should dedent old_doc with inspect.cleandoc instead of textwrap.dedent, as the first line may not be indented... e.g. right now (before this PR) the docstring of backend_cairo.ArrayWrapper.__init__ is

.. deprecated:: 3.0
    The ArrayWrapper class was deprecated in Matplotlib 3.0 and will be removed in 3.2.

Thin wrapper around numpy ndarray to expose the interface
       expected by cairocffi. Basically replicates the
       array.array interface.

The latter would fail if the first line is not indented, which occurs.
@NelleV NelleV merged commit 0c144fd into matplotlib:master Sep 21, 2018
@NelleV
Copy link
Member

NelleV commented Sep 21, 2018

Thanks @anntzer !

@anntzer anntzer deleted the classmethod-deprecation branch September 22, 2018 08:11
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.

5 participants