On Fri, Sep 3, 2021 at 12:45 AM Peter Otten <__pete...@web.de> wrote:
>
> On 02/09/2021 11:41, Chris Angelico wrote:
> > On Thu, Sep 2, 2021 at 7:36 PM Peter Otten <__pete...@web.de> wrote:
> >>
> >> On 02/09/2021 04:32, Steven D'Aprano wrote:
> >>> On Wed, Sep 01, 2021 at 03:40:37PM +0200, Peter Otten wrote:
> >>>
> >>>> Instead of removing it you might add a filter to get a similar effect:
> >>>
> >>> [...]
> >>>
> >>>>>>> warnings.filterwarnings("always", "woof!")
> >>>
> >>> Unfortunately that's too aggressive. In my use-case, `bark` will be
> >>> called many, many times in a loop, and so potentially "woof" will be
> >>> displayed over and over again. That will be annoying.
>
> >> Then use filterwarnings("once", ...):
>
> > That has the side effect that all OTHER warnings get their onceness
> > reset too though.
>
> Oops, insufficient testing. But I really didn't expect that...
>
> > (It's actually the same as resetfilters, and for the same reason -
> > whenever the filters change, all oncenesses get forgotten.)
>
> Could be changed (I'm tempted to say fixed)?
>

Not sure. I don't think __warningregistry__ is meant to be manipulated
other than by the warnings module itself. (It gets a single passing
mention in the docs, nothing more.) The solution would be pretty
simple, and technically *can* be done from the calling module, but I
think a warnings.forget() function would be the best way to do it.

I'm disinclined to change the behaviour of resetfilters and filter
changes in general (they bump a version number, and if the registry
has an older version, it's ignored), but adding a separate function to
forget a single warning would be backward compatible.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/IGUWF6BX6PS6NFO6KO7RPQKWKCP3QWZQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to