71
79
one_one = "%s was deprecated in version 1.1."
72
80
one_two = "%s was deprecated in version 1.2."
73
81
one_three = "%s was deprecated in version 1.3."
82
one_four = "%s was deprecated in version 1.4."
83
one_five = "%s was deprecated in version 1.5."
84
one_six = "%s was deprecated in version 1.6."
87
def deprecated_in(version_tuple):
88
"""Generate a message that something was deprecated in a release.
90
>>> deprecated_in((1, 4, 0))
91
'%s was deprecated in version 1.4.'
93
return ("%%s was deprecated in version %s."
94
% bzrlib._format_version_tuple(version_tuple))
75
97
def set_warning_method(method):
76
98
"""Set the warning method to be used by this module.
169
191
# we cannot just forward to a new method name.I.e. in the following
170
192
# examples we would want to have callers that pass any value to 'bad' be
171
193
# given a warning - because we have applied:
172
# @deprecated_parameter('bad', zero_seven)
194
# @deprecated_parameter('bad', deprecated_in((1, 5, 0))
174
196
# def __init__(self, bad=None)
175
197
# def __init__(self, bad, other)
238
260
"""Create a dict that warns when read or modified.
240
:param deprecation_version: something like zero_nine
262
:param deprecation_version: string for the warning format to raise,
263
typically from deprecated_in()
241
264
:param initial_value: The contents of the dict
242
265
:param variable_name: This allows better warnings to be printed
243
266
:param advice: String of advice on what callers should do instead
262
285
initial_value, extra=None):
263
286
"""Create a list that warns when modified
265
:param deprecation_version: something like zero_nine
288
:param deprecation_version: string for the warning format to raise,
289
typically from deprecated_in()
266
290
:param initial_value: The contents of the list
267
291
:param variable_name: This allows better warnings to be printed
268
292
:param extra: Extra info to print when printing a warning
307
331
return self._warn_deprecated(list.pop)
309
333
return _DeprecatedList(initial_value)
336
def _check_for_filter(error_only):
337
"""Check if there is already a filter for deprecation warnings.
339
:param error_only: Only match an 'error' filter
340
:return: True if a filter is found, False otherwise
343
for filter in warnings.filters:
344
if issubclass(DeprecationWarning, filter[2]):
345
# This filter will effect DeprecationWarning
346
if not error_only or filter[0] == 'error':
351
def suppress_deprecation_warnings(override=True):
352
"""Call this function to suppress all deprecation warnings.
354
When this is a final release version, we don't want to annoy users with
355
lots of deprecation warnings. We only want the deprecation warnings when
356
running a dev or release candidate.
358
:param override: If True, always set the ignore, if False, only set the
359
ignore if there isn't already a filter.
362
if not override and _check_for_filter(error_only=False):
363
# If there is already a filter effecting suppress_deprecation_warnings,
366
warnings.filterwarnings('ignore', category=DeprecationWarning)
369
def activate_deprecation_warnings(override=True):
370
"""Call this function to activate deprecation warnings.
372
When running in a 'final' release we suppress deprecation warnings.
373
However, the test suite wants to see them. So when running selftest, we
374
re-enable the deprecation warnings.
376
Note: warnings that have already been issued under 'ignore' will not be
377
reported after this point. The 'warnings' module has already marked them as
378
handled, so they don't get issued again.
380
:param override: If False, only add a filter if there isn't an error filter
381
already. (This slightly differs from suppress_deprecation_warnings, in
382
because it always overrides everything but -Werror).
385
if not override and _check_for_filter(error_only=True):
386
# DeprecationWarnings are already turned into errors, don't downgrade
389
warnings.filterwarnings('default', category=DeprecationWarning)