diff options
| author | Michele Simionato <michele.simionato@gmail.com> | 2015-07-19 07:36:08 +0200 |
|---|---|---|
| committer | Michele Simionato <michele.simionato@gmail.com> | 2015-07-19 07:36:08 +0200 |
| commit | 79c669ce71afcd70b49344823b5ccc8a61023f98 (patch) | |
| tree | 804468b4ce1810ba0502a5b53a60c8815711b12f /src | |
| parent | da7b6d12e18d4d123db61a74c933d5106db59465 (diff) | |
| download | python-decorator-git-79c669ce71afcd70b49344823b5ccc8a61023f98.tar.gz | |
Unified the documentation for Python 2 and 3
Diffstat (limited to 'src')
| -rw-r--r-- | src/decorator.py | 20 |
1 files changed, 7 insertions, 13 deletions
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) |
