On Wed, Sep 01, 2021 at 05:27:40PM +1000, Steven D'Aprano wrote:
Maybe I'm missing something, but I don't think that there is anyway to remove a warning from the warnings filter list so that it will be shown again.
Example:
>>> import warnings >>> warnings.warn("something happened") <stdin>:1: UserWarning: something happened >>> warnings.warn("something happened") >>>
Once a warning has been displayed, it won't be displayed again until you exit the interpreter and start a new session. That's usually what we want, but sometimes I do want to re-display the warning.
The warnings module has a function, reset_warnings, but it does too much, removing all the filters including those set at interpreter startup. I'd like a function to remove a single item, something like this:
>>> warnings.warn("something happened") <stdin>:1: UserWarning: something happened >>> warnings.warn("something happened") >>> >>> warnings.forget(UserWarning("something happened")) >>> warnings.warn("something happened") <stdin>:1: UserWarning: something happened
or similar.
Thoughts?
Sounds like a missing feature. Zbyszek