This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients michael.foord, ncoghlan, pitrou
Date 2011-03-23.02:04:37
SpamBayes Score 1.0983287e-06
Marked as misclassified No
Message-id <1300845878.3.0.475491224846.issue11647@psf.upfronthosting.co.za>
In-reply-to
Content
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...
History
Date User Action Args
2011-03-23 02:04:38pitrousetrecipients: + pitrou, ncoghlan, michael.foord
2011-03-23 02:04:38pitrousetmessageid: <1300845878.3.0.475491224846.issue11647@psf.upfronthosting.co.za>
2011-03-23 02:04:37pitroulinkissue11647 messages
2011-03-23 02:04:37pitroucreate