3173.1.3
by Martin Pool
Deprecate disable_default_logging and add 1.2 deprecation marker |
1 |
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
|
2227.1.5
by mbp at sourcefrog
doc cleanup |
2 |
# Authors: Robert Collins <robert.collins@canonical.com> and others
|
1534.2.1
by Robert Collins
Implement deprecated_method |
3 |
#
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
"""Symbol versioning
|
|
19 |
||
20 |
The methods here allow for api symbol versioning.
|
|
21 |
"""
|
|
22 |
||
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
23 |
__all__ = ['deprecated_function', |
3388.1.2
by Martin Pool
Add new symbol_versioning.deprecated_in |
24 |
'deprecated_in', |
1836.1.12
by John Arbash Meinel
Move ignores into a file of their own, make DEFAULT_IGNORE a deprecated list. Create deprecated_list in symbol versioning. |
25 |
'deprecated_list', |
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
26 |
'deprecated_method', |
1534.4.32
by Robert Collins
Rename deprecated_nonce to DEPRECATED_PARAMETER |
27 |
'DEPRECATED_PARAMETER', |
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
28 |
'deprecated_passed', |
3400.3.1
by Martin Pool
Remove methods deprecated in zero_eight |
29 |
'set_warning_method', |
30 |
'warn', |
|
3400.3.6
by Martin Pool
Remove code deprecated prior to 1.1 and its tests |
31 |
'zero_seven', |
32 |
'zero_eight', |
|
33 |
'zero_nine', |
|
1852.11.1
by Robert Collins
Deprecate compare_trees and move its body to InterTree.changes_from. |
34 |
'zero_ten', |
1711.9.6
by John Arbash Meinel
Add a deprecation symbol for bzr-0.11 |
35 |
'zero_eleven', |
2037.1.2
by Robert Collins
(Robert Collins) Add 0.12 deprecation symbol. |
36 |
'zero_twelve', |
2101.1.2
by John Arbash Meinel
Create the 0.13 deprecation symbol |
37 |
'zero_thirteen', |
2150.1.1
by Wouter van Heyst
bzr 0.13rc1 has branch, bump bzr.dev version to 0.14 |
38 |
'zero_fourteen', |
2234.1.1
by Wouter van Heyst
0.14rc1 has branch, bump bzr.dev version to 0.15 |
39 |
'zero_fifteen', |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
40 |
'zero_sixteen', |
2483.1.2
by John Arbash Meinel
Updates for bzr-0.17-dev |
41 |
'zero_seventeen', |
2524.1.1
by Aaron Bentley
Revert broken changes |
42 |
'zero_eighteen', |
2687.2.1
by Martin Pool
Rename upcoming release from 0.19 to 0.90 |
43 |
'zero_ninety', |
2697.1.1
by John Arbash Meinel
Switch bzr.dev to 0.91 development |
44 |
'zero_ninetyone', |
2830.2.5
by Martin Pool
Deprecated ``run_bzr_decode``; use the new ``output_encoding`` parameter to |
45 |
'zero_ninetytwo', |
2955.3.1
by Alexander Belchenko
start 0.93 development cycle; deprecate osutils.backup_file |
46 |
'zero_ninetythree', |
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
47 |
'one_zero', |
48 |
'one_one', |
|
3173.1.3
by Martin Pool
Deprecate disable_default_logging and add 1.2 deprecation marker |
49 |
'one_two', |
3221.2.1
by Martin Pool
Open 1.3 development |
50 |
'one_three', |
3287.5.5
by Robert Collins
Refactor internals of knit implementations to implement get_parents_with_ghosts in terms of get_parent_map. |
51 |
'one_four', |
3256.2.29
by Daniel Watkins
Added symbol_versioning.one_five. |
52 |
'one_five', |
3422.1.2
by John Arbash Meinel
Update version in 'bzr' and 'bzrlib/__init__.py' |
53 |
'one_six', |
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
54 |
]
|
1534.2.1
by Robert Collins
Implement deprecated_method |
55 |
|
56 |
from warnings import warn |
|
57 |
||
3388.1.2
by Martin Pool
Add new symbol_versioning.deprecated_in |
58 |
import bzrlib |
59 |
||
1534.2.1
by Robert Collins
Implement deprecated_method |
60 |
|
1534.4.32
by Robert Collins
Rename deprecated_nonce to DEPRECATED_PARAMETER |
61 |
DEPRECATED_PARAMETER = "A deprecated parameter marker." |
3400.3.6
by Martin Pool
Remove code deprecated prior to 1.1 and its tests |
62 |
zero_seven = "%s was deprecated in version 0.7." |
63 |
zero_eight = "%s was deprecated in version 0.8." |
|
64 |
zero_nine = "%s was deprecated in version 0.9." |
|
1852.11.1
by Robert Collins
Deprecate compare_trees and move its body to InterTree.changes_from. |
65 |
zero_ten = "%s was deprecated in version 0.10." |
1711.9.6
by John Arbash Meinel
Add a deprecation symbol for bzr-0.11 |
66 |
zero_eleven = "%s was deprecated in version 0.11." |
2037.1.2
by Robert Collins
(Robert Collins) Add 0.12 deprecation symbol. |
67 |
zero_twelve = "%s was deprecated in version 0.12." |
2116.1.1
by James Westby
Fix string for deprecation warning for 0.13 |
68 |
zero_thirteen = "%s was deprecated in version 0.13." |
2150.1.1
by Wouter van Heyst
bzr 0.13rc1 has branch, bump bzr.dev version to 0.14 |
69 |
zero_fourteen = "%s was deprecated in version 0.14." |
2234.1.1
by Wouter van Heyst
0.14rc1 has branch, bump bzr.dev version to 0.15 |
70 |
zero_fifteen = "%s was deprecated in version 0.15." |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
71 |
zero_sixteen = "%s was deprecated in version 0.16." |
2483.1.2
by John Arbash Meinel
Updates for bzr-0.17-dev |
72 |
zero_seventeen = "%s was deprecated in version 0.17." |
2524.1.1
by Aaron Bentley
Revert broken changes |
73 |
zero_eighteen = "%s was deprecated in version 0.18." |
2687.2.2
by Martin Pool
Fix up other references to 0.19 |
74 |
zero_ninety = "%s was deprecated in version 0.90." |
2697.1.1
by John Arbash Meinel
Switch bzr.dev to 0.91 development |
75 |
zero_ninetyone = "%s was deprecated in version 0.91." |
2830.2.5
by Martin Pool
Deprecated ``run_bzr_decode``; use the new ``output_encoding`` parameter to |
76 |
zero_ninetytwo = "%s was deprecated in version 0.92." |
3123.1.1
by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation. |
77 |
one_zero = "%s was deprecated in version 1.0." |
78 |
zero_ninetythree = one_zero # Maintained for backwards compatibility |
|
79 |
one_one = "%s was deprecated in version 1.1." |
|
3173.1.3
by Martin Pool
Deprecate disable_default_logging and add 1.2 deprecation marker |
80 |
one_two = "%s was deprecated in version 1.2." |
3221.2.1
by Martin Pool
Open 1.3 development |
81 |
one_three = "%s was deprecated in version 1.3." |
3293.1.1
by Martin Pool
Add one_four deprecation |
82 |
one_four = "%s was deprecated in version 1.4." |
3256.2.29
by Daniel Watkins
Added symbol_versioning.one_five. |
83 |
one_five = "%s was deprecated in version 1.5." |
3422.1.2
by John Arbash Meinel
Update version in 'bzr' and 'bzrlib/__init__.py' |
84 |
one_six = "%s was deprecated in version 1.6." |
1534.2.1
by Robert Collins
Implement deprecated_method |
85 |
|
3388.1.2
by Martin Pool
Add new symbol_versioning.deprecated_in |
86 |
|
87 |
def deprecated_in(version_tuple): |
|
88 |
"""Generate a message that something was deprecated in a release.
|
|
89 |
||
90 |
>>> deprecated_in((1, 4, 0))
|
|
3427.2.5
by John Arbash Meinel
Change deprecated_in to end with a '.' |
91 |
'%s was deprecated in version 1.4.'
|
3388.1.2
by Martin Pool
Add new symbol_versioning.deprecated_in |
92 |
"""
|
3427.2.5
by John Arbash Meinel
Change deprecated_in to end with a '.' |
93 |
return ("%%s was deprecated in version %s." |
94 |
% bzrlib._format_version_tuple(version_tuple)) |
|
3388.1.2
by Martin Pool
Add new symbol_versioning.deprecated_in |
95 |
|
1534.2.1
by Robert Collins
Implement deprecated_method |
96 |
|
97 |
def set_warning_method(method): |
|
98 |
"""Set the warning method to be used by this module.
|
|
99 |
||
100 |
It should take a message and a warning category as warnings.warn does.
|
|
101 |
"""
|
|
102 |
global warn |
|
103 |
warn = method |
|
104 |
||
105 |
||
1534.2.2
by Robert Collins
Implement deprecated_function. |
106 |
# TODO - maybe this would be easier to use as one 'smart' method that
|
107 |
# guess if it is a method or a class or an attribute ? If so, we can
|
|
108 |
# add that on top of the primitives, once we have all three written
|
|
109 |
# - RBC 20050105
|
|
110 |
||
1982.3.1
by Robert Collins
New utility function symbol_versioning.deprecation_string. Returns the |
111 |
|
112 |
def deprecation_string(a_callable, deprecation_version): |
|
113 |
"""Generate an automatic deprecation string for a_callable.
|
|
114 |
||
115 |
:param a_callable: The callable to substitute into deprecation_version.
|
|
116 |
:param deprecation_version: A deprecation format warning string. This should
|
|
117 |
have a single %s operator in it. a_callable will be turned into a nice
|
|
118 |
python symbol and then substituted into deprecation_version.
|
|
119 |
"""
|
|
2872.5.1
by Martin Pool
Avoid internal error tracebacks on failure to lock on readonly transport (#129701). |
120 |
# We also want to handle old-style classes, in particular exception, and
|
121 |
# they don't have an im_class attribute.
|
|
1982.3.1
by Robert Collins
New utility function symbol_versioning.deprecation_string. Returns the |
122 |
if getattr(a_callable, 'im_class', None) is None: |
123 |
symbol = "%s.%s" % (a_callable.__module__, |
|
124 |
a_callable.__name__) |
|
125 |
else: |
|
126 |
symbol = "%s.%s.%s" % (a_callable.im_class.__module__, |
|
127 |
a_callable.im_class.__name__, |
|
128 |
a_callable.__name__ |
|
129 |
)
|
|
130 |
return deprecation_version % symbol |
|
131 |
||
132 |
||
1534.2.2
by Robert Collins
Implement deprecated_function. |
133 |
def deprecated_function(deprecation_version): |
134 |
"""Decorate a function so that use of it will trigger a warning."""
|
|
135 |
||
136 |
def function_decorator(callable): |
|
137 |
"""This is the function python calls to perform the decoration."""
|
|
138 |
||
139 |
def decorated_function(*args, **kwargs): |
|
1534.2.3
by Robert Collins
decorate docstrings in deprecated functions. |
140 |
"""This is the decorated function."""
|
3530.2.2
by John Arbash Meinel
Add extra debugging for when a deprecated function/method are called |
141 |
from bzrlib import trace |
142 |
trace.mutter_callsite(4, "Deprecated function called") |
|
1982.3.1
by Robert Collins
New utility function symbol_versioning.deprecation_string. Returns the |
143 |
warn(deprecation_string(callable, deprecation_version), |
144 |
DeprecationWarning, stacklevel=2) |
|
1534.2.2
by Robert Collins
Implement deprecated_function. |
145 |
return callable(*args, **kwargs) |
1534.2.5
by Robert Collins
Set the __name__ attribute on decorated methods and functions. |
146 |
_populate_decorated(callable, deprecation_version, "function", |
1534.2.3
by Robert Collins
decorate docstrings in deprecated functions. |
147 |
decorated_function) |
1534.2.2
by Robert Collins
Implement deprecated_function. |
148 |
return decorated_function |
149 |
return function_decorator |
|
150 |
||
151 |
||
1534.2.1
by Robert Collins
Implement deprecated_method |
152 |
def deprecated_method(deprecation_version): |
153 |
"""Decorate a method so that use of it will trigger a warning.
|
|
2825.3.2
by Martin Pool
doc |
154 |
|
155 |
To deprecate a static or class method, use
|
|
156 |
||
157 |
@staticmethod
|
|
158 |
@deprecated_function
|
|
159 |
def ...
|
|
1534.2.1
by Robert Collins
Implement deprecated_method |
160 |
|
161 |
To deprecate an entire class, decorate __init__.
|
|
162 |
"""
|
|
163 |
||
164 |
def method_decorator(callable): |
|
165 |
"""This is the function python calls to perform the decoration."""
|
|
166 |
||
167 |
def decorated_method(self, *args, **kwargs): |
|
168 |
"""This is the decorated method."""
|
|
3530.2.2
by John Arbash Meinel
Add extra debugging for when a deprecated function/method are called |
169 |
from bzrlib import trace |
2872.5.1
by Martin Pool
Avoid internal error tracebacks on failure to lock on readonly transport (#129701). |
170 |
if callable.__name__ == '__init__': |
171 |
symbol = "%s.%s" % (self.__class__.__module__, |
|
172 |
self.__class__.__name__, |
|
173 |
)
|
|
174 |
else: |
|
175 |
symbol = "%s.%s.%s" % (self.__class__.__module__, |
|
176 |
self.__class__.__name__, |
|
177 |
callable.__name__ |
|
178 |
)
|
|
3530.2.2
by John Arbash Meinel
Add extra debugging for when a deprecated function/method are called |
179 |
trace.mutter_callsite(4, "Deprecated method called") |
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
180 |
warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2) |
1534.2.1
by Robert Collins
Implement deprecated_method |
181 |
return callable(self, *args, **kwargs) |
1534.2.5
by Robert Collins
Set the __name__ attribute on decorated methods and functions. |
182 |
_populate_decorated(callable, deprecation_version, "method", |
1534.2.3
by Robert Collins
decorate docstrings in deprecated functions. |
183 |
decorated_method) |
1534.2.1
by Robert Collins
Implement deprecated_method |
184 |
return decorated_method |
185 |
return method_decorator |
|
1534.2.3
by Robert Collins
decorate docstrings in deprecated functions. |
186 |
|
187 |
||
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
188 |
def deprecated_passed(parameter_value): |
189 |
"""Return True if parameter_value was used."""
|
|
190 |
# FIXME: it might be nice to have a parameter deprecation decorator.
|
|
191 |
# it would need to handle positional and *args and **kwargs parameters,
|
|
192 |
# which means some mechanism to describe how the parameter was being
|
|
193 |
# passed before deprecation, and some way to deprecate parameters that
|
|
194 |
# were not at the end of the arg list. Thats needed for __init__ where
|
|
195 |
# we cannot just forward to a new method name.I.e. in the following
|
|
196 |
# examples we would want to have callers that pass any value to 'bad' be
|
|
197 |
# given a warning - because we have applied:
|
|
3400.3.4
by Martin Pool
Remove zero_seven deprecations |
198 |
# @deprecated_parameter('bad', deprecated_in((1, 5, 0))
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
199 |
#
|
200 |
# def __init__(self, bad=None)
|
|
201 |
# def __init__(self, bad, other)
|
|
202 |
# def __init__(self, **kwargs)
|
|
203 |
# RBC 20060116
|
|
1534.4.32
by Robert Collins
Rename deprecated_nonce to DEPRECATED_PARAMETER |
204 |
return not parameter_value is DEPRECATED_PARAMETER |
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
205 |
|
206 |
||
1534.2.3
by Robert Collins
decorate docstrings in deprecated functions. |
207 |
def _decorate_docstring(callable, deprecation_version, label, |
208 |
decorated_callable): |
|
1732.1.1
by John Arbash Meinel
deprecating appendpath, it does exactly what pathjoin does |
209 |
if callable.__doc__: |
210 |
docstring_lines = callable.__doc__.split('\n') |
|
211 |
else: |
|
212 |
docstring_lines = [] |
|
1534.2.3
by Robert Collins
decorate docstrings in deprecated functions. |
213 |
if len(docstring_lines) == 0: |
214 |
decorated_callable.__doc__ = deprecation_version % ("This " + label) |
|
215 |
elif len(docstring_lines) == 1: |
|
216 |
decorated_callable.__doc__ = (callable.__doc__ |
|
217 |
+ "\n" |
|
218 |
+ "\n" |
|
219 |
+ deprecation_version % ("This " + label) |
|
220 |
+ "\n") |
|
221 |
else: |
|
222 |
spaces = len(docstring_lines[-1]) |
|
223 |
new_doc = callable.__doc__ |
|
224 |
new_doc += "\n" + " " * spaces |
|
225 |
new_doc += deprecation_version % ("This " + label) |
|
226 |
new_doc += "\n" + " " * spaces |
|
227 |
decorated_callable.__doc__ = new_doc |
|
1534.2.5
by Robert Collins
Set the __name__ attribute on decorated methods and functions. |
228 |
|
229 |
||
230 |
def _populate_decorated(callable, deprecation_version, label, |
|
231 |
decorated_callable): |
|
232 |
"""Populate attributes like __name__ and __doc__ on the decorated callable.
|
|
233 |
"""
|
|
234 |
_decorate_docstring(callable, deprecation_version, label, |
|
235 |
decorated_callable) |
|
1534.1.3
by Robert Collins
Bugfix the symbol_versioning deprecation decorators to update the |
236 |
decorated_callable.__module__ = callable.__module__ |
1534.2.5
by Robert Collins
Set the __name__ attribute on decorated methods and functions. |
237 |
decorated_callable.__name__ = callable.__name__ |
1581.1.1
by Robert Collins
Bugfix aliases to be backwards compatible with plugins providing command.run_argv. |
238 |
decorated_callable.is_deprecated = True |
1836.1.12
by John Arbash Meinel
Move ignores into a file of their own, make DEFAULT_IGNORE a deprecated list. Create deprecated_list in symbol versioning. |
239 |
|
240 |
||
2227.1.5
by mbp at sourcefrog
doc cleanup |
241 |
def _dict_deprecation_wrapper(wrapped_method): |
2227.1.2
by mbp at sourcefrog
Add a simple DeprecatedDict class |
242 |
"""Returns a closure that emits a warning and calls the superclass"""
|
243 |
def cb(dep_dict, *args, **kwargs): |
|
244 |
msg = 'access to %s' % (dep_dict._variable_name, ) |
|
245 |
msg = dep_dict._deprecation_version % (msg,) |
|
246 |
if dep_dict._advice: |
|
247 |
msg += ' ' + dep_dict._advice |
|
248 |
warn(msg, DeprecationWarning, stacklevel=2) |
|
2227.1.5
by mbp at sourcefrog
doc cleanup |
249 |
return wrapped_method(dep_dict, *args, **kwargs) |
2227.1.2
by mbp at sourcefrog
Add a simple DeprecatedDict class |
250 |
return cb |
251 |
||
252 |
||
253 |
class DeprecatedDict(dict): |
|
254 |
"""A dictionary that complains when read or written."""
|
|
255 |
||
256 |
is_deprecated = True |
|
257 |
||
258 |
def __init__(self, |
|
259 |
deprecation_version, |
|
260 |
variable_name, |
|
261 |
initial_value, |
|
262 |
advice, |
|
263 |
):
|
|
264 |
"""Create a dict that warns when read or modified.
|
|
265 |
||
3400.3.5
by Martin Pool
Remove zero_nine deprecations |
266 |
:param deprecation_version: string for the warning format to raise,
|
267 |
typically from deprecated_in()
|
|
2227.1.2
by mbp at sourcefrog
Add a simple DeprecatedDict class |
268 |
:param initial_value: The contents of the dict
|
269 |
:param variable_name: This allows better warnings to be printed
|
|
270 |
:param advice: String of advice on what callers should do instead
|
|
271 |
of using this variable.
|
|
272 |
"""
|
|
273 |
self._deprecation_version = deprecation_version |
|
274 |
self._variable_name = variable_name |
|
275 |
self._advice = advice |
|
276 |
dict.__init__(self, initial_value) |
|
277 |
||
278 |
# This isn't every possible method but it should trap anyone using the
|
|
279 |
# dict -- add more if desired
|
|
280 |
__len__ = _dict_deprecation_wrapper(dict.__len__) |
|
281 |
__getitem__ = _dict_deprecation_wrapper(dict.__getitem__) |
|
282 |
__setitem__ = _dict_deprecation_wrapper(dict.__setitem__) |
|
283 |
__delitem__ = _dict_deprecation_wrapper(dict.__delitem__) |
|
284 |
keys = _dict_deprecation_wrapper(dict.keys) |
|
285 |
__contains__ = _dict_deprecation_wrapper(dict.__contains__) |
|
286 |
||
287 |
||
1836.1.12
by John Arbash Meinel
Move ignores into a file of their own, make DEFAULT_IGNORE a deprecated list. Create deprecated_list in symbol versioning. |
288 |
def deprecated_list(deprecation_version, variable_name, |
289 |
initial_value, extra=None): |
|
290 |
"""Create a list that warns when modified
|
|
291 |
||
3400.3.5
by Martin Pool
Remove zero_nine deprecations |
292 |
:param deprecation_version: string for the warning format to raise,
|
293 |
typically from deprecated_in()
|
|
1836.1.12
by John Arbash Meinel
Move ignores into a file of their own, make DEFAULT_IGNORE a deprecated list. Create deprecated_list in symbol versioning. |
294 |
:param initial_value: The contents of the list
|
295 |
:param variable_name: This allows better warnings to be printed
|
|
296 |
:param extra: Extra info to print when printing a warning
|
|
297 |
"""
|
|
298 |
||
299 |
subst_text = 'Modifying %s' % (variable_name,) |
|
300 |
msg = deprecation_version % (subst_text,) |
|
301 |
if extra: |
|
302 |
msg += ' ' + extra |
|
303 |
||
304 |
class _DeprecatedList(list): |
|
305 |
__doc__ = list.__doc__ + msg |
|
306 |
||
307 |
is_deprecated = True |
|
308 |
||
309 |
def _warn_deprecated(self, func, *args, **kwargs): |
|
310 |
warn(msg, DeprecationWarning, stacklevel=3) |
|
311 |
return func(self, *args, **kwargs) |
|
312 |
||
313 |
def append(self, obj): |
|
314 |
"""appending to %s is deprecated""" % (variable_name,) |
|
315 |
return self._warn_deprecated(list.append, obj) |
|
316 |
||
317 |
def insert(self, index, obj): |
|
318 |
"""inserting to %s is deprecated""" % (variable_name,) |
|
319 |
return self._warn_deprecated(list.insert, index, obj) |
|
320 |
||
321 |
def extend(self, iterable): |
|
322 |
"""extending %s is deprecated""" % (variable_name,) |
|
323 |
return self._warn_deprecated(list.extend, iterable) |
|
324 |
||
325 |
def remove(self, value): |
|
326 |
"""removing from %s is deprecated""" % (variable_name,) |
|
327 |
return self._warn_deprecated(list.remove, value) |
|
328 |
||
329 |
def pop(self, index=None): |
|
330 |
"""pop'ing from from %s is deprecated""" % (variable_name,) |
|
331 |
if index: |
|
332 |
return self._warn_deprecated(list.pop, index) |
|
333 |
else: |
|
334 |
# Can't pass None
|
|
335 |
return self._warn_deprecated(list.pop) |
|
336 |
||
337 |
return _DeprecatedList(initial_value) |
|
3427.5.1
by John Arbash Meinel
Have the bzrlib.commands.main() function suppress deprecation warnings when running a final release. |
338 |
|
339 |
||
3427.5.5
by John Arbash Meinel
Disable suppression if there is already a filter present for Warnings |
340 |
def _check_for_filter(error_only): |
341 |
"""Check if there is already a filter for deprecation warnings.
|
|
342 |
|
|
343 |
:param error_only: Only match an 'error' filter
|
|
344 |
:return: True if a filter is found, False otherwise
|
|
345 |
"""
|
|
346 |
import warnings |
|
347 |
for filter in warnings.filters: |
|
348 |
if issubclass(DeprecationWarning, filter[2]): |
|
349 |
# This filter will effect DeprecationWarning
|
|
350 |
if not error_only or filter[0] == 'error': |
|
351 |
return True |
|
352 |
return False |
|
353 |
||
354 |
||
3427.5.7
by John Arbash Meinel
Bring back always in the form of 'override'. |
355 |
def suppress_deprecation_warnings(override=True): |
3427.5.1
by John Arbash Meinel
Have the bzrlib.commands.main() function suppress deprecation warnings when running a final release. |
356 |
"""Call this function to suppress all deprecation warnings.
|
357 |
||
358 |
When this is a final release version, we don't want to annoy users with
|
|
359 |
lots of deprecation warnings. We only want the deprecation warnings when
|
|
360 |
running a dev or release candidate.
|
|
3427.5.7
by John Arbash Meinel
Bring back always in the form of 'override'. |
361 |
|
362 |
:param override: If True, always set the ignore, if False, only set the
|
|
363 |
ignore if there isn't already a filter.
|
|
3427.5.1
by John Arbash Meinel
Have the bzrlib.commands.main() function suppress deprecation warnings when running a final release. |
364 |
"""
|
365 |
import warnings |
|
3427.5.7
by John Arbash Meinel
Bring back always in the form of 'override'. |
366 |
if not override and _check_for_filter(error_only=False): |
3427.5.5
by John Arbash Meinel
Disable suppression if there is already a filter present for Warnings |
367 |
# If there is already a filter effecting suppress_deprecation_warnings,
|
368 |
# then skip it.
|
|
369 |
return
|
|
3427.5.1
by John Arbash Meinel
Have the bzrlib.commands.main() function suppress deprecation warnings when running a final release. |
370 |
warnings.filterwarnings('ignore', category=DeprecationWarning) |
371 |
||
372 |
||
3427.5.7
by John Arbash Meinel
Bring back always in the form of 'override'. |
373 |
def activate_deprecation_warnings(override=True): |
3427.5.1
by John Arbash Meinel
Have the bzrlib.commands.main() function suppress deprecation warnings when running a final release. |
374 |
"""Call this function to activate deprecation warnings.
|
375 |
||
376 |
When running in a 'final' release we suppress deprecation warnings.
|
|
377 |
However, the test suite wants to see them. So when running selftest, we
|
|
378 |
re-enable the deprecation warnings.
|
|
379 |
||
380 |
Note: warnings that have already been issued under 'ignore' will not be
|
|
381 |
reported after this point. The 'warnings' module has already marked them as
|
|
382 |
handled, so they don't get issued again.
|
|
3427.5.7
by John Arbash Meinel
Bring back always in the form of 'override'. |
383 |
|
384 |
:param override: If False, only add a filter if there isn't an error filter
|
|
385 |
already. (This slightly differs from suppress_deprecation_warnings, in
|
|
386 |
because it always overrides everything but -Werror).
|
|
3427.5.1
by John Arbash Meinel
Have the bzrlib.commands.main() function suppress deprecation warnings when running a final release. |
387 |
"""
|
388 |
import warnings |
|
3427.5.7
by John Arbash Meinel
Bring back always in the form of 'override'. |
389 |
if not override and _check_for_filter(error_only=True): |
3427.5.5
by John Arbash Meinel
Disable suppression if there is already a filter present for Warnings |
390 |
# DeprecationWarnings are already turned into errors, don't downgrade
|
391 |
# them to 'default'.
|
|
392 |
return
|
|
3427.5.1
by John Arbash Meinel
Have the bzrlib.commands.main() function suppress deprecation warnings when running a final release. |
393 |
warnings.filterwarnings('default', category=DeprecationWarning) |