333
333
return _DeprecatedList(initial_value)
336
def suppress_deprecation_warnings():
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):
337
352
"""Call this function to suppress all deprecation warnings.
339
354
When this is a final release version, we don't want to annoy users with
340
355
lots of deprecation warnings. We only want the deprecation warnings when
341
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,
344
366
warnings.filterwarnings('ignore', category=DeprecationWarning)
347
def activate_deprecation_warnings():
369
def activate_deprecation_warnings(override=True):
348
370
"""Call this function to activate deprecation warnings.
350
372
When running in a 'final' release we suppress deprecation warnings.
354
376
Note: warnings that have already been issued under 'ignore' will not be
355
377
reported after this point. The 'warnings' module has already marked them as
356
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
359
389
warnings.filterwarnings('default', category=DeprecationWarning)