[New-bugs-announce] [issue11647] function decorated with a context manager can only be invoked once
Antoine Pitrou
report at bugs.python.org
Wed Mar 23 03:04:38 CET 2011
New submission from Antoine Pitrou <pitrou at free.fr>:
If you add the following test to text_contextlib:
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -363,6 +363,8 @@ class TestContextDecorator(unittest.Test
state.append(x)
test('something')
self.assertEqual(state, [1, 'something', 999])
+ test('something else')
+ self.assertEqual(state, [1, 'something', 999, 1, 'something else', 999])
# This is needed to make the test actually run under regrtest.py!
You get the following error:
======================================================================
ERROR: test_contextmanager_as_decorator (test.test_contextlib.TestContextDecorator)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/cpython/32/Lib/contextlib.py", line 28, in __enter__
return next(self.gen)
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/antoine/cpython/32/Lib/test/test_contextlib.py", line 366, in test_contextmanager_as_decorator
test('something else')
File "/home/antoine/cpython/32/Lib/contextlib.py", line 15, in inner
with self:
File "/home/antoine/cpython/32/Lib/contextlib.py", line 30, in __enter__
raise RuntimeError("generator didn't yield")
RuntimeError: generator didn't yield
Clearly there is a problem in the API or its implementation, as in a function decorated with a context manager can only be invoked once! This isn't good...
----------
components: Library (Lib)
messages: 131838
nosy: michael.foord, ncoghlan, pitrou
priority: normal
severity: normal
status: open
title: function decorated with a context manager can only be invoked once
type: behavior
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11647>
_______________________________________
More information about the New-bugs-announce
mailing list