From 483ebae0c0c425e90d4ff4f32fe02cb96cd11621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 11 Mar 2013 23:18:54 +0100 Subject: [PATCH] Change deprecated decorator to display warning in doc string --- skimage/_shared/utils.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/skimage/_shared/utils.py b/skimage/_shared/utils.py index 4075ddb4..6518f40b 100644 --- a/skimage/_shared/utils.py +++ b/skimage/_shared/utils.py @@ -6,7 +6,7 @@ __all__ = ['deprecated'] class deprecated(object): - """Decorator to mark deprecated functions with warning. + '''Decorator to mark deprecated functions with warning. Adapted from . @@ -17,7 +17,7 @@ class deprecated(object): behavior : {'warn', 'raise'} Behavior during call to deprecated function: 'warn' = warn user that function is deprecated; 'raise' = raise error. - """ + ''' def __init__(self, alt_func=None, behavior='warn'): self.alt_func = alt_func @@ -25,9 +25,9 @@ class deprecated(object): def __call__(self, func): - msg = "Call to deprecated function `%s`." % func.__name__ + msg = 'Call to deprecated function `%s`.' % func.__name__ if self.alt_func is not None: - msg = msg + " Use `%s` instead." % self.alt_func + msg += ' Use `%s` instead.' % self.alt_func @functools.wraps(func) def wrapped(*args, **kwargs): @@ -40,4 +40,14 @@ class deprecated(object): raise DeprecationWarning(msg) return func(*args, **kwargs) + # modify doc string to display deprecation warning + doc = 'Deprecated function.' + if self.alt_func is not None: + doc += ' Use `%s` instead.' % self.alt_func + + if wrapped.__doc__ is None: + wrapped.__doc__ = doc + else: + wrapped.__doc__ = doc + '\n\n' + wrapped.__doc__ + return wrapped