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 1/4] 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 From 0cb0fee339883adeb93f787b5cc19e5293463c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 11 Mar 2013 23:21:52 +0100 Subject: [PATCH 2/4] Remove duplicate code for alternative function --- skimage/_shared/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/skimage/_shared/utils.py b/skimage/_shared/utils.py index 6518f40b..102d4214 100644 --- a/skimage/_shared/utils.py +++ b/skimage/_shared/utils.py @@ -25,9 +25,12 @@ class deprecated(object): def __call__(self, func): - msg = 'Call to deprecated function `%s`.' % func.__name__ + alt_msg = '' if self.alt_func is not None: - msg += ' Use `%s` instead.' % self.alt_func + alt_msg = ' Use `%s` instead.' % self.alt_func + + msg = 'Call to deprecated function `%s`.' % func.__name__ + msg += alt_msg @functools.wraps(func) def wrapped(*args, **kwargs): @@ -41,10 +44,7 @@ class deprecated(object): 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 - + doc = 'Deprecated function.' + alt_msg if wrapped.__doc__ is None: wrapped.__doc__ = doc else: From a0d9d3f213fb28914040e9647509c897ad8cc41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 12 Mar 2013 07:28:15 +0100 Subject: [PATCH 3/4] Use double instead of single quotes for doc string --- skimage/_shared/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/_shared/utils.py b/skimage/_shared/utils.py index 102d4214..fc13c7e6 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 From 332c21f97936baab6901fccb3b6d28eaee83729c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 12 Mar 2013 07:29:39 +0100 Subject: [PATCH 4/4] Make deprecation warning in doc string bold --- skimage/_shared/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/_shared/utils.py b/skimage/_shared/utils.py index fc13c7e6..acdf9c16 100644 --- a/skimage/_shared/utils.py +++ b/skimage/_shared/utils.py @@ -44,7 +44,7 @@ class deprecated(object): return func(*args, **kwargs) # modify doc string to display deprecation warning - doc = 'Deprecated function.' + alt_msg + doc = '**Deprecated function**.' + alt_msg if wrapped.__doc__ is None: wrapped.__doc__ = doc else: