all Python 3warningsfunction
warnings.resetwarnings()
filters
Removes every warning filter rule — the ones added in code, the ones set with -W, and the built-in defaults.
Syntax
warnings.resetwarnings()
The catch is "and the defaults": after a reset the filter list is empty, the 'default' action applies to everything, and DeprecationWarning and ImportWarning, normally hidden, suddenly show up. Whatever the user set via -W or PYTHONWARNINGS is gone too, so a library must never call it. To restore settings after temporary changes use catch_warnings(), not this.
Examples
import warnings
with warnings.catch_warnings():
warnings.resetwarnings()
print(warnings.filters) # → []
print(len(warnings.filters) > 0) # → True
import warnings
with warnings.catch_warnings(record=True) as caught:
warnings.resetwarnings()
warnings.warn('старый вызов', DeprecationWarning)
print(caught[0].category.__name__) # → DeprecationWarning
See also
Open in the full glossarydocs.python.orgReport an inaccuracy