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 <>
If you add the following test to text_contextlib:

diff --git a/Lib/test/ b/Lib/test/
--- a/Lib/test/
+++ b/Lib/test/
@@ -363,6 +363,8 @@ class TestContextDecorator(unittest.Test
         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!

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/", line 28, in __enter__
    return next(self.gen)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/antoine/cpython/32/Lib/test/", line 366, in test_contextmanager_as_decorator
    test('something else')
  File "/home/antoine/cpython/32/Lib/", line 15, in inner
    with self:
  File "/home/antoine/cpython/32/Lib/", 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...
Date User Action Args
2011-03-23 02:04:38pitrousetrecipients: + pitrou, ncoghlan, michael.foord
2011-03-23 02:04:38pitrousetmessageid: <>
2011-03-23 02:04:37pitroulinkissue11647 messages
2011-03-23 02:04:37pitroucreate