cpython: b23d1df7e47e (original) (raw)

Mercurial > cpython

changeset 69850:b23d1df7e47e

Merge #11647 update from 3.2 [#11647]

Nick Coghlan ncoghlan@gmail.com
date Thu, 05 May 2011 23:58:57 +1000
parents 97004f70ff0d(current diff)e4ba097123f6(diff)
children b06d7aa8ac20
files Misc/ACKS Misc/NEWS
diffstat 6 files changed, 50 insertions(+), 10 deletions(-)[+] [-] Doc/library/contextlib.rst 14 Lib/contextlib.py 28 Lib/test/test_contextlib.py 7 Lib/test/test_with.py 6 Misc/ACKS 1 Misc/NEWS 4

line wrap: on

line diff

--- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -54,8 +54,12 @@ Functions provided: the exception has been handled, and execution will resume with the statement immediately following the :keyword:with statement.

+ .. versionadded:: 3.2

--- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -9,10 +9,23 @@ from warnings import warn class ContextDecorator(object): "A base class or mixin that enables context managers to work as decorators." +

+ def call(self, func): @wraps(func) def inner(*args, **kwds):

@@ -20,8 +33,15 @@ class ContextDecorator(object): class _GeneratorContextManager(ContextDecorator): """Helper for @contextmanager decorator."""

+

def enter(self): try: @@ -92,7 +112,7 @@ def contextmanager(func): """ @wraps(func) def helper(*args, **kwds):

--- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -350,13 +350,13 @@ class TestContextDecorator(unittest.Test def test_contextmanager_as_decorator(self):

@@ -364,6 +364,11 @@ class TestContextDecorator(unittest.Test test('something') self.assertEqual(state, [1, 'something', 999])

+

This is needed to make the test actually run under regrtest.py

def test_main():

--- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -14,8 +14,8 @@ from test.support import run_unittest class MockContextManager(_GeneratorContextManager):

@@ -33,7 +33,7 @@ class MockContextManager(_GeneratorConte def mock_contextmanager(func): def helper(*args, **kwds):

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -709,6 +709,7 @@ Burton Radons Brodie Rao Antti Rasinen Sridhar Ratnakumar +Ysj Ray Eric Raymond Edward K. Ream Chris Rebert

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -140,6 +140,10 @@ Core and Builtins Library ------- +- Issue #11647: objects created using contextlib.contextmanager now support