[issue29672] `catch_warnings` context manager causes all warnings to be printed every time, even after exiting

2021-04-02 Thread Tom Aldcroft


Tom Aldcroft  added the comment:

I encountered this issue today and want to +1 getting some attention on this.

The disconnected nature of this issue makes it especially difficult to 
understand -- any package in the stack can change this hidden global variable 
`_filters_version` in the warnings module that then impacts the local behavior 
of warnings in the user script.

The only way I was able to finally understand that an update to an obscure 
dependency was breaking our regression testing was by reading the `warnings` 
source code and then monkey patching it to print diagnostic information.

Even a documentation update would be useful. This could explain not only 
`catch_warnings()`, but in general the unexpected feature that if any package 
anywhere in the stack sets a warning filter, then that globally resets whether 
a warning has been seen before (via the call to `_filters_mutated()`).

--
nosy: +taldcroft
versions:  -Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29672] `catch_warnings` context manager causes all warnings to be printed every time, even after exiting

2018-07-10 Thread Segev Finer


Change by Segev Finer :


--
keywords: +patch
pull_requests: +7769
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29672] `catch_warnings` context manager causes all warnings to be printed every time, even after exiting

2018-07-10 Thread Erik Bray


Erik Bray  added the comment:

Yes, I think `catch_warnings` should back up and restore the relevant 
`__warningregistry__`.  At which point it's not even clear to me what value 
there is in the _filter_version...

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29672] `catch_warnings` context manager causes all warnings to be printed every time, even after exiting

2018-07-10 Thread Segev Finer


Segev Finer  added the comment:

Hmm, I originally missed the per module __warningregistry__... Need to read the 
code more closely...

What should the behavior be? We can add a flag that will make all warning 
actions be "always" when catch_warnings is in effect. But that doesn't feel 
right with the way catch_warnings currently behaves or what is expected of it.

Another idea would be to add a callback that is called whenever we set a module 
registry, allowing catch_warnings to backup the original registry of each 
module and restore them all on exit (Also the _onceregistry and 
_filters_version).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29672] `catch_warnings` context manager causes all warnings to be printed every time, even after exiting

2018-06-28 Thread Erik Bray


Erik Bray  added the comment:

I just encountered this as well.  The way catch_warnings is implemented is a 
bit "dumb" in how it treats _filter_version (it calls _filters_mutated even if 
the active filters are not actually changed when entering catch_warnings).

More significantly, _filter_version is not fine-grained enough.  If some 
warning was already displayed, calling catch_warnings() should not later cause 
that same warning to be displayed again unless the filters were modified in 
such a way, during catch_warnings(), that that warning should be displayed 
(e.g. changed to 'always').

I'm not really sure what to do about that though.  Maybe the "filter version" 
should be per-warning?  Currently the value assigned to each warning in 
__warningregistry__ is not used (it is just set to True), so maybe that could 
actually be used for this.

--
nosy: +erik.bray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29672] `catch_warnings` context manager causes all warnings to be printed every time, even after exiting

2017-07-21 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
nosy: +pitrou, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29672] `catch_warnings` context manager causes all warnings to be printed every time, even after exiting

2017-07-21 Thread Segev Finer

Segev Finer added the comment:

I think you will need to save and restore _filters_version and _onceregistry. 
Since _filters_version is a static variable in _warnings.c you will probably 
also have to modify it somehow to make it accessible to warnings.py.

--
components: +Library (Lib)
nosy: +Segev Finer
type:  -> behavior
versions: +Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29672] `catch_warnings` context manager causes all warnings to be printed every time, even after exiting

2017-07-18 Thread Gerrit Holl

Changes by Gerrit Holl :


--
title: `catch_warnings` context manager should reset warning registry to 
previous state upon exiting, to prevent warnings from being reprinted -> 
`catch_warnings` context manager causes all warnings to be printed every time, 
even after exiting

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com