Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Don't split creation of deprecation message and choice of warning class. #12995

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
Dec 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions 30 lib/matplotlib/cbook/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MatplotlibDeprecationWarning(UserWarning):
"""mplDeprecation is deprecated. Use MatplotlibDeprecationWarning instead."""


def _generate_deprecation_message(
def _generate_deprecation_warning(
since, message='', name='', alternative='', pending=False,
obj_type='attribute', addendum='', *, removal=''):

Expand All @@ -34,7 +34,7 @@ def _generate_deprecation_message(

if not message:
message = (
"The %(name)s %(obj_type)s"
"\nThe %(name)s %(obj_type)s"
Copy link
Member

Choose a reason for hiding this comment

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

IIRC we had a discussion some time ago that we do not want warnings and logs to introduce newlines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want one and still don't, but @dstansby argued in favor of it so there's one right now in warn_deprecated (so I put one here as well) but none in deprecated. I decided to leave it in as I don't care enough to argue about that, but either way it should be consistent between the two cases.

+ (" will be deprecated in a future version"
if pending else
(" was deprecated in Matplotlib %(since)s"
Expand All @@ -45,9 +45,12 @@ def _generate_deprecation_message(
+ (" Use %(alternative)s instead." if alternative else "")
+ (" %(addendum)s" if addendum else ""))

return message % dict(
warning_cls = (PendingDeprecationWarning if pending
else MatplotlibDeprecationWarning)

return warning_cls(message % dict(
func=name, name=name, obj_type=obj_type, since=since, removal=removal,
alternative=alternative, addendum=addendum)
alternative=alternative, addendum=addendum))


def warn_deprecated(
Expand Down Expand Up @@ -101,15 +104,12 @@ def warn_deprecated(
# To warn of the deprecation of "matplotlib.name_of_module"
warn_deprecated('1.4.0', name='matplotlib.name_of_module',
obj_type='module')

"""
message = '\n' + _generate_deprecation_message(
warning = _generate_deprecation_warning(
since, message, name, alternative, pending, obj_type, addendum,
removal=removal)
category = (PendingDeprecationWarning if pending
else MatplotlibDeprecationWarning)
from . import _warn_external
_warn_external(message, category)
_warn_external(warning)


def deprecated(since, *, message='', name='', alternative='', pending=False,
Expand Down Expand Up @@ -203,19 +203,19 @@ class _deprecated_property(property):
def __get__(self, instance, owner):
if instance is not None:
from . import _warn_external
_warn_external(message, category)
_warn_external(warning)
return super().__get__(instance, owner)

def __set__(self, instance, value):
if instance is not None:
from . import _warn_external
_warn_external(message, category)
_warn_external(warning)
return super().__set__(instance, value)

def __delete__(self, instance):
if instance is not None:
from . import _warn_external
_warn_external(message, category)
_warn_external(warning)
return super().__delete__(instance)

def finalize(_, new_doc):
Expand All @@ -233,15 +233,13 @@ def finalize(wrapper, new_doc):
wrapper.__doc__ = new_doc
return wrapper

message = _generate_deprecation_message(
warning = _generate_deprecation_warning(
since, message, name, alternative, pending, obj_type, addendum,
removal=removal)
category = (PendingDeprecationWarning if pending
else MatplotlibDeprecationWarning)

def wrapper(*args, **kwargs):
from . import _warn_external
_warn_external(message, category)
_warn_external(warning)
return func(*args, **kwargs)

old_doc = inspect.cleandoc(old_doc or '').strip('\n')
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.