From 79c669ce71afcd70b49344823b5ccc8a61023f98 Mon Sep 17 00:00:00 2001 From: Michele Simionato Date: Sun, 19 Jul 2015 07:36:08 +0200 Subject: Unified the documentation for Python 2 and 3 --- src/decorator.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/decorator.py b/src/decorator.py index 2e14027..96de525 100644 --- a/src/decorator.py +++ b/src/decorator.py @@ -244,7 +244,7 @@ def decorator(caller, func=None): # ####################### contextmanager ####################### # def __call__(self, func): - 'Context manager decorator' + """Context manager decorator""" return FunctionMaker.create( func, "with _self_: return _func_(%(shortsignature)s)", dict(_self_=self, _func_=func), __wrapped__=func) @@ -258,17 +258,11 @@ try: # Python >= 3.2 except ImportError: # Python >= 2.5 - try: - from contextlib import GeneratorContextManager - except ImportError: # Python 2.4 - class ContextManager(object): - def __init__(self, g, *a, **k): - raise RuntimeError( - 'You cannot used contextmanager in Python 2.4!') - else: - class ContextManager(GeneratorContextManager): - def __init__(self, g, *a, **k): - return GeneratorContextManager.__init__(self, g(*a, **k)) - __call__ = __call__ + from contextlib import GeneratorContextManager + + class ContextManager(GeneratorContextManager): + def __init__(self, g, *a, **k): + return GeneratorContextManager.__init__(self, g(*a, **k)) + __call__ = __call__ contextmanager = decorator(ContextManager) -- cgit v1.2.1