[pypy-commit] pypy py3.5: test and fix a warning
arigo
pypy.commits at gmail.com
Tue Nov 29 03:55:53 EST 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88723:2958f07abe78
Date: 2016-11-29 09:55 +0100
http://bitbucket.org/pypy/pypy/changeset/2958f07abe78/
Log: test and fix a warning
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -20,7 +20,8 @@
self.running = False
self._name = name # may be null, use get_name()
self._qualname = qualname # may be null, use get_qualname()
- if self.pycode.co_flags & CO_YIELD_INSIDE_TRY:
+ if (isinstance(self, Coroutine) # XXX would be cool not to need this
+ or self.pycode.co_flags & CO_YIELD_INSIDE_TRY):
self.register_finalizer(self.space)
self.saved_operr = None
@@ -385,7 +386,7 @@
self.frame.last_instr == -1:
space = self.space
msg = u"coroutine '%s' was never awaited" % self.get_qualname()
- space.warn(space.w_RuntimeWarning, space.wrap(msg))
+ space.warn(space.wrap(msg), space.w_RuntimeWarning)
GeneratorOrCoroutine._finalize_(self)
diff --git a/pypy/interpreter/test/test_coroutine.py b/pypy/interpreter/test/test_coroutine.py
--- a/pypy/interpreter/test/test_coroutine.py
+++ b/pypy/interpreter/test/test_coroutine.py
@@ -160,3 +160,20 @@
else:
assert False, "should have raised"
"""
+
+ def test_runtime_warning(self): """
+ import gc, warnings
+ async def foobaz():
+ pass
+ with warnings.catch_warnings(record=True) as l:
+ foobaz()
+ gc.collect()
+ gc.collect()
+ gc.collect()
+
+ assert len(l) == 1, repr(l)
+ w = l[0].message
+ assert isinstance(w, RuntimeWarning)
+ assert str(w).startswith("coroutine ")
+ assert str(w).endswith("foobaz' was never awaited")
+ """
More information about the pypy-commit
mailing list