-Wonce does not seem to work correctly
There is a failing test around unittests that boils down to the difference between cpython and pypy on this code (save as /tmp/test.py
)
#Run with -Wonce
import warnings
print('----------------------------')
warnings.warn(
'warning warning',
DeprecationWarning, 2)
warnings.warn(
'warning warning',
DeprecationWarning, 2)
warnings.warn(
'warning warning',
DeprecationWarning, 2)
def _deprecate(original_func):
def deprecated_func(*args, **kwargs):
warnings.warn(
'Please use {0} instead.'.format(original_func.__name__),
DeprecationWarning, 2)
return original_func(*args, **kwargs)
return deprecated_func
def func1():
pass
func2 = _deprecate(func1)
print('----------------------------')
func2()
func2()
func2()
func2()
CPython3 -Wonce prints
----------------------------
sys:1: DeprecationWarning: warning warning
----------------------------
/tmp/test.py:32: DeprecationWarning: Please use func1 instead.
func2()
PyPy 3.7 -Wonce print
----------------------------
sys:1: DeprecationWarning: warning warning
----------------------------
/tmp/stam.py:32: DeprecationWarning: Please use func1 instead.
func2()
/tmp/stam.py:33: DeprecationWarning: Please use func1 instead.
func2()
/tmp/stam.py:34: DeprecationWarning: Please use func1 instead.
func2()
/tmp/stam.py:35: DeprecationWarning: Please use func1 instead.
func2()
If I disable the built-in _warnings
module the output is identical.