From 963a2912e8a673eb0c0fc9d82a41d55b72abe756 Mon Sep 17 00:00:00 2001 From: Michele Simionato Date: Fri, 20 Aug 2021 07:55:21 +0200 Subject: Fixed bug in decorator.contextmanager --- CHANGES.md | 4 +++- src/decorator.py | 4 ++-- src/tests/documentation.py | 4 ++-- 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 -- cgit v1.2.1