69
71
"""Generate an automatic deprecation string for a_callable.
71
73
:param a_callable: The callable to substitute into deprecation_version.
72
:param deprecation_version: A deprecation format warning string. This
73
should have a single %s operator in it. a_callable will be turned into
74
a nice python symbol and then substituted into deprecation_version.
74
:param deprecation_version: A deprecation format warning string. This should
75
have a single %s operator in it. a_callable will be turned into a nice
76
python symbol and then substituted into deprecation_version.
76
if getattr(a_callable, '__self__', None) is not None:
78
# We also want to handle old-style classes, in particular exception, and
79
# they don't have an im_class attribute.
80
if getattr(a_callable, 'im_class', None) is None:
81
symbol = "%s.%s" % (a_callable.__module__,
77
84
symbol = "%s.%s.%s" % (a_callable.__self__.__class__.__module__,
78
85
a_callable.__self__.__class__.__name__,
80
elif getattr(a_callable, '__qualname__', None) is not None and '<' not in a_callable.__qualname__:
81
symbol = "%s.%s" % (a_callable.__module__,
82
a_callable.__qualname__)
84
symbol = "%s.%s" % (a_callable.__module__,
86
88
return deprecation_version % symbol
97
99
from . import trace
98
100
trace.mutter_callsite(4, "Deprecated function called")
99
101
warn(deprecation_string(callable, deprecation_version),
100
DeprecationWarning, stacklevel=2)
102
DeprecationWarning, stacklevel=2)
101
103
return callable(*args, **kwargs)
102
104
_populate_decorated(callable, deprecation_version, "function",
103
105
decorated_function)
133
135
callable.__name__
135
137
trace.mutter_callsite(4, "Deprecated method called")
136
warn(deprecation_version %
137
symbol, DeprecationWarning, stacklevel=2)
138
warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2)
138
139
return callable(self, *args, **kwargs)
139
140
_populate_decorated(callable, deprecation_version, "method",
140
141
decorated_method)
158
159
# def __init__(self, bad, other)
159
160
# def __init__(self, **kwargs)
161
return parameter_value is not DEPRECATED_PARAMETER
162
return not parameter_value is DEPRECATED_PARAMETER
164
165
def _decorate_docstring(callable, deprecation_version, label,
170
171
if len(docstring_lines) == 0:
171
172
decorated_callable.__doc__ = deprecation_version % ("This " + label)
172
173
elif len(docstring_lines) == 1:
173
decorated_callable.__doc__ = (
174
callable.__doc__ + "\n" + "\n" +
175
deprecation_version % ("This " + label) + "\n")
174
decorated_callable.__doc__ = (callable.__doc__
177
+ deprecation_version % ("This " + label)
177
180
spaces = len(docstring_lines[-1])
178
181
new_doc = callable.__doc__