aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Friedrich Bolz-Tereick <cfbolz@gmx.de>2021-10-15 14:59:32 +0200
committerCarl Friedrich Bolz-Tereick <cfbolz@gmx.de>2021-10-15 14:59:32 +0200
commit578068abb3aafbe021ad11d4dc7780e794f9a84b (patch)
tree97ccfce4bdbcb3e9dd74f1e24dbc97bf23df30c2
parentmerge py3.7 into release (diff)
downloadpypy-release-pypy3.7-v7.3.6.tar.gz
pypy-release-pypy3.7-v7.3.6.tar.bz2
pypy-release-pypy3.7-v7.3.6.zip
fix bug in 1138b6754bdd: the "if" of an elif chain was moved, attaching therelease-pypy3.7-v7.3.6
elif to the previous if and breaking "once" in the process, under some circumstances
-rw-r--r--pypy/module/_warnings/interp_warnings.py3
-rw-r--r--pypy/module/_warnings/test/apptest_warnings.py14
2 files changed, 16 insertions, 1 deletions
diff --git a/pypy/module/_warnings/interp_warnings.py b/pypy/module/_warnings/interp_warnings.py
index c89f524575..4f9dc0c2a1 100644
--- a/pypy/module/_warnings/interp_warnings.py
+++ b/pypy/module/_warnings/interp_warnings.py
@@ -323,7 +323,8 @@ def do_warn_explicit(space, w_category, w_message, context_w,
if action != 'always':
if not space.is_w(w_registry, space.w_None):
space.setitem(w_registry, w_key, space.w_True)
- elif action == 'once':
+
+ if action == 'once':
if space.is_w(w_registry, space.w_None):
w_registry = get_once_registry(space)
warned = update_registry(space, w_registry, w_text, w_category)
diff --git a/pypy/module/_warnings/test/apptest_warnings.py b/pypy/module/_warnings/test/apptest_warnings.py
index 5e6607c5e0..434002c269 100644
--- a/pypy/module/_warnings/test/apptest_warnings.py
+++ b/pypy/module/_warnings/test/apptest_warnings.py
@@ -173,3 +173,17 @@ def test_issue31285():
'eggs', UserWarning, 'bar', 1,
module_globals={'__loader__': get_bad_loader(42),
'__name__': 'foobar'})
+
+def test_once_is_not_broken():
+ def f():
+ warnings.warn("deprecated", DeprecationWarning, 2)
+
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("once")
+ assert len(w) == 0
+ f()
+ assert len(w) == 1
+ f()
+ assert len(w) == 1
+ f()
+ assert len(w) == 1