-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
lib/matplotlib/cbook/deprecation.py
Outdated
new_doc = (('\n.. deprecated:: %(since)s' | ||
'\n %(message)s\n\n' % | ||
{'since': since, 'message': message}) + old_doc) | ||
new_doc = ('.. deprecated:: {}\n' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8abe9f6
to
167ede8
Compare
new_doc = (('\n.. deprecated:: %(since)s' | ||
'\n %(message)s\n\n' % | ||
{'since': since, 'message': message}) + old_doc) | ||
new_doc = ('.. deprecated:: {since}\n' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Thanks @anntzer ! |
The
@deprecated
decorator has a branch for handling deprecation ofclassmethods, but that won't ever work because we start by getting
the
__name__
attribute on the object, which raises an AttributeErroron classmethods.
This could be fixed by fetching
obj.__func__.__name__
instead, butgiven that one can as well put the
@deprecated
decorator under the@classmethod
decorator (so that it sees the underlying function), wecan just remove that non-functioning code.
Also switch some docstring formatting to str.format.
PR Summary
PR Checklist