配置 IPython 以始终显示警告

xnx*_*xnx 8 python ipython

我第一次做一些在 IPython shell 中引发警告的事情时,我看到了。但随后的时间我没有。例如,

In [1]: import numpy as np
In [2]: np.uint8(250) * np.uint8(2)
/Users/me/anaconda/envs/py33/bin/ipython:1: RuntimeWarning: overflow encountered in ubyte_scalars
#!/bin/bash /Users/me/anaconda/envs/py33/bin/python.app
Out[2]: 244

In [3]: np.uint8(250) * np.uint8(2)
Out[3]: 244       # No warning!
Run Code Online (Sandbox Code Playgroud)

如何配置 IPython 以始终显示警告?我试过了:

import warnings
warnings.filterwarnings('always')
Run Code Online (Sandbox Code Playgroud)

但这没有任何区别。

DSM*_*DSM 9

我认为IPython 团队最近解决了这个问题。warnings由于一个有点不寻常的设计决定,它并没有很好地发挥作用。always在纯 Python 中打开图灵就足够了,现在如果我在 IPython 主干中做同样的事情:

In [1]: import warnings

In [2]: warnings.filterwarnings('always')

In [3]: import numpy as np

In [4]: np.uint8(250) * np.uint8(2)
/home/dsm/sys/root/bin/ipython3.4:1: RuntimeWarning: overflow encountered in ubyte_scalars
  #!/home/dsm/sys/root/bin/python3.4
Out[4]: 244

In [5]: np.uint8(250) * np.uint8(2)
/home/dsm/sys/root/bin/ipython3.4:1: RuntimeWarning: overflow encountered in ubyte_scalars
  #!/home/dsm/sys/root/bin/python3.4
Out[5]: 244
Run Code Online (Sandbox Code Playgroud)