diff options
author | Michele Simionato <michele.simionato@gmail.com> | 2021-08-20 07:56:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-20 07:56:58 +0200 |
commit | 590b55de8040c3af6600443030f0dc43180514c9 (patch) | |
tree | 0fc64234ec282c025277f52176666ea63c704902 | |
parent | 9ff37744f33a5aaf9459c7a9b3c9062f6952c349 (diff) | |
parent | 963a2912e8a673eb0c0fc9d82a41d55b72abe756 (diff) | |
download | python-decorator-git-590b55de8040c3af6600443030f0dc43180514c9.tar.gz |
Merge pull request #131 from micheles/contextmanager
Fixed bug in decorator.contextmanager
-rw-r--r-- | CHANGES.md | 4 | ||||
-rw-r--r-- | src/decorator.py | 4 | ||||
-rw-r--r-- | src/tests/documentation.py | 4 |
3 files changed, 7 insertions, 5 deletions
@@ -3,7 +3,9 @@ HISTORY ## unreleased -decorator.decorator was not passing the kwsyntax. +`decorator.decorator` was not passing the kwsyntax argument. +Functions decorated with `decorator.contextmanager` were one-shot. +This is now fixed, thanks to Alex Pizarro for the report. ## 5.0.9 (2021-05-16) diff --git a/src/decorator.py b/src/decorator.py index dab0d7c..9435841 100644 --- a/src/decorator.py +++ b/src/decorator.py @@ -294,11 +294,11 @@ def decorator(caller, _func=None, kwsyntax=False): class ContextManager(_GeneratorContextManager): def __init__(self, g, *a, **k): - return _GeneratorContextManager.__init__(self, g, a, k) + _GeneratorContextManager.__init__(self, g, a, k) def __call__(self, func): def caller(f, *a, **k): - with self: + with self._recreate_cm(): return f(*a, **k) return decorate(func, caller) diff --git a/src/tests/documentation.py b/src/tests/documentation.py index 4fa5c9d..5323c4e 100644 --- a/src/tests/documentation.py +++ b/src/tests/documentation.py @@ -599,11 +599,11 @@ a ``__call__`` method, so that they can be used as decorators, like so: ```python >>> ba = before_after('BEFORE', 'AFTER') >>> ->>> @ba # doctest: +SKIP +>>> @ba ... def hello(): ... print('hello') ... ->>> hello() # doctest: +SKIP +>>> hello() BEFORE hello AFTER |