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.
Once it has been displayed *once* in that loop, it shouldn't be
displayed again for the rest of the loop.
Also, `bark` is being called from a comprehension or sort key
function, so it is difficult to keep an explicit flag myself:
# My use case is *not* this
def process(values):
seen = False
for item in values:
if condition:
if seen: bark()
seen = True
# More like this:
sorted(values, key=func) # func may call bark
Allowing `bark` to *always* display could be annoying. Ideally I want it
to be displayed *at most* once per call to sorted(). I can do that by
removing the filter after sorting. Or at least I could if it were
possible to remove individual filters.
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/LT5HNFPSWF4S7A6QRUZZOU4OMOYFKKLS/
Code of Conduct: http://python.org/psf/codeofconduct/