mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
Issue #11647: allow contextmanager objects to be used as decorators as described in the docs. Initial patch by Ysj Ray.
This commit is contained in:
parent
f77b74dd1b
commit
0ded3e307b
6 changed files with 50 additions and 10 deletions
|
@ -14,8 +14,8 @@ from test.support import run_unittest
|
|||
|
||||
|
||||
class MockContextManager(_GeneratorContextManager):
|
||||
def __init__(self, gen):
|
||||
_GeneratorContextManager.__init__(self, gen)
|
||||
def __init__(self, func, *args, **kwds):
|
||||
super().__init__(func, *args, **kwds)
|
||||
self.enter_called = False
|
||||
self.exit_called = False
|
||||
self.exit_args = None
|
||||
|
@ -33,7 +33,7 @@ class MockContextManager(_GeneratorContextManager):
|
|||
|
||||
def mock_contextmanager(func):
|
||||
def helper(*args, **kwds):
|
||||
return MockContextManager(func(*args, **kwds))
|
||||
return MockContextManager(func, *args, **kwds)
|
||||
return helper
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue