summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2021-08-20 07:55:21 +0200
committerMichele Simionato <michele.simionato@gmail.com>2021-08-20 07:55:21 +0200
commit963a2912e8a673eb0c0fc9d82a41d55b72abe756 (patch)
tree0fc64234ec282c025277f52176666ea63c704902
parent9ff37744f33a5aaf9459c7a9b3c9062f6952c349 (diff)
downloadpython-decorator-git-963a2912e8a673eb0c0fc9d82a41d55b72abe756.tar.gz
Fixed bug in decorator.contextmanager
-rw-r--r--CHANGES.md4
-rw-r--r--src/decorator.py4
-rw-r--r--src/tests/documentation.py4
3 files changed, 7 insertions, 5 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 876df34..21510d6 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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