-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Python 3: warnings displayed multiple times despite default 'once' filter #11207
Copy link
Copy link
Open
Description
(I suspect this has come up before but I couldn't find an existing issue for it.)
The expected default behavior in Python for handling warnings is such that once a specific warning has been displayed once, it should not be displayed again (unless the warning filters are updated). E.g.:
Python 3.6.1 (default, Feb 21 2018, 12:59:49)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import warnings
>>> def foo():
... warnings.warn('foo')
...
>>> foo()
__main__:2: UserWarning: foo
>>> foo()
>>>
However, in IPython CLI this behavior is not observed (probably same for the notebook but I haven't tested):
Python 3.6.1 (default, Feb 21 2018, 12:59:49)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import warnings
In [2]: def foo():
...: warnings.warn('foo')
...:
In [3]: foo()
.../local/bin/ipython3:2: UserWarning: foo
# EASY-INSTALL-ENTRY-SCRIPT: 'ipython==5.5.0','console_scripts','ipython3'
In [4]: foo()
.../local/bin/ipython3:2: UserWarning: foo
# EASY-INSTALL-ENTRY-SCRIPT: 'ipython==5.5.0','console_scripts','ipython3'
I have documented the cause of this behavior here, and I believe it is more of a CPython bug than an IPython bug. But it's possible there's a workaround that could be applied, or at the very least I thought the issue should be noted.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels