145
146
decorated_callable.__module__ = callable.__module__
146
147
decorated_callable.__name__ = callable.__name__
147
148
decorated_callable.is_deprecated = True
151
def deprecated_list(deprecation_version, variable_name,
152
initial_value, extra=None):
153
"""Create a list that warns when modified
155
:param deprecation_version: something like zero_nine
156
:param initial_value: The contents of the list
157
:param variable_name: This allows better warnings to be printed
158
:param extra: Extra info to print when printing a warning
161
subst_text = 'Modifying %s' % (variable_name,)
162
msg = deprecation_version % (subst_text,)
166
class _DeprecatedList(list):
167
__doc__ = list.__doc__ + msg
171
def _warn_deprecated(self, func, *args, **kwargs):
172
warn(msg, DeprecationWarning, stacklevel=3)
173
return func(self, *args, **kwargs)
175
def append(self, obj):
176
"""appending to %s is deprecated""" % (variable_name,)
177
return self._warn_deprecated(list.append, obj)
179
def insert(self, index, obj):
180
"""inserting to %s is deprecated""" % (variable_name,)
181
return self._warn_deprecated(list.insert, index, obj)
183
def extend(self, iterable):
184
"""extending %s is deprecated""" % (variable_name,)
185
return self._warn_deprecated(list.extend, iterable)
187
def remove(self, value):
188
"""removing from %s is deprecated""" % (variable_name,)
189
return self._warn_deprecated(list.remove, value)
191
def pop(self, index=None):
192
"""pop'ing from from %s is deprecated""" % (variable_name,)
194
return self._warn_deprecated(list.pop, index)
197
return self._warn_deprecated(list.pop)
199
return _DeprecatedList(initial_value)