Sometimes you just can't mute python warnings. Use this library to solve this.
pip install shutup
At the beginning of your code (before you import other things), add this line:
import shutup; shutup.please()
That's it. Enjoy the silence :)
If your warnings were not silenced, please open an issue. PRs, ideas and other contributions are also welcome.
You can use:
shutup.jk()
to re-enable warnings if you need them.
You can also use:
shutup.mute_warnings()
shutup.unmute_warnings()
They are the same as the functions above, but they have cleaner (but arguably less funny) names.
Context managers are also supported:
import shutup
shutup.mute_warnings()
# Annoying code
with shutup.unmute_warnings:
# code that doesn't cry wolf
Note that you shouldn't use ()
in a context manager:
with shutup.mute_warnings: # correct
with shutup.mute_warnings(): # wrong
When context managers exit, they will reset warnings to muted/unmuted based on their state before entering.
⚠️ Note that muting and unmutting is not a thread safe operation.