diff options
author | michele.simionato <devnull@localhost> | 2009-08-18 04:14:35 +0000 |
---|---|---|
committer | michele.simionato <devnull@localhost> | 2009-08-18 04:14:35 +0000 |
commit | b07f7636cf14d9512ddb79057e592ae9583952db (patch) | |
tree | a3bb2e7428a905146c6daf2ed0ae30d1f479f82e /decorator | |
parent | a9759e6f47df13f25de488a9f7b45eb70723a403 (diff) | |
download | micheles-b07f7636cf14d9512ddb79057e592ae9583952db.tar.gz |
Decorator 3.1.1
Diffstat (limited to 'decorator')
-rwxr-xr-x | decorator/CHANGES.txt | 2 | ||||
-rwxr-xr-x | decorator/decorator.py | 25 | ||||
-rw-r--r-- | decorator/documentation.py | 13 | ||||
-rw-r--r-- | decorator/setup.py | 2 |
4 files changed, 32 insertions, 10 deletions
diff --git a/decorator/CHANGES.txt b/decorator/CHANGES.txt index 00ccdef..3dfed71 100755 --- a/decorator/CHANGES.txt +++ b/decorator/CHANGES.txt @@ -1,6 +1,8 @@ HISTORY ---------- +3.1.1. Fixed a bug which was breaking Pylons, signaled by + Gabriel de Perthuis, and added a test for it. (18/08/2009) 3.1. Added decorator.factory, an easy way to define families of decorators (requested by various users, including David Laban). Refactored the FunctionMaker class and added an easier to use .create classmethod. diff --git a/decorator/decorator.py b/decorator/decorator.py index 780c13a..5c81350 100755 --- a/decorator/decorator.py +++ b/decorator/decorator.py @@ -28,19 +28,23 @@ Decorator module, see http://pypi.python.org/pypi/decorator for the documentation. """ -__all__ = ["decorator", "FunctionMaker", "deprecated", "getinfo", "new_wrapper"] +__all__ = ["decorator", "FunctionMaker", "partial", + "deprecated", "getinfo", "new_wrapper"] import os, sys, re, inspect, warnings try: from functools import partial except ImportError: # for Python version < 2.5 class partial(object): - "A poor man replacement of partial for use in the decorator module only" - def __init__(self, func, *args): + "A simple replacement of functools.partial" + def __init__(self, func, *args, **kw): self.func = func - self.args = args - def __call__(self, *otherargs): - return self.func(*(self.args + otherargs)) + self.args = args + self.keywords = kw + def __call__(self, *otherargs, **otherkw): + kw = self.keywords.copy() + kw.update(otherkw) + return self.func(*(self.args + otherargs), **kw) DEF = re.compile('\s*def\s*([_\w][_\w\d]*)\s*\(') @@ -151,7 +155,14 @@ def decorator(caller, func=None): func, "return _call_(_func_, %(signature)s)", dict(_call_=caller, _func_=func), undecorated=func) else: # returns a decorator - return partial(decorator, caller) + if isinstance(caller, partial): + return partial(decorator, caller) + # otherwise assume caller is a function + f = inspect.getargspec(caller)[0][0] # first arg + return FunctionMaker.create( + '%s(%s)' % (caller.__name__, f), + 'return decorator(_call_, %s)' % f, + dict(_call_=caller, decorator=decorator), undecorated=caller) ###################### deprecated functionality ######################### diff --git a/decorator/documentation.py b/decorator/documentation.py index 0005d9c..192ebfb 100644 --- a/decorator/documentation.py +++ b/decorator/documentation.py @@ -281,7 +281,7 @@ object which can be used as a decorator: .. code-block:: python >>> trace # doctest: +ELLIPSIS - <functools.partial object at 0x...> + <function trace at 0x...> Here is an example of usage: @@ -837,8 +837,8 @@ you are unhappy with it, send me a patch! """ from __future__ import with_statement import sys, threading, time, functools, inspect, itertools -from functools import partial from decorator import * +from functools import partial from setup import VERSION today = time.strftime('%Y-%m-%d') @@ -1056,5 +1056,14 @@ def fact(n): # this is not tail-recursive if n == 0: return 1 return n * fact(n-1) + +def atest_for_pylons(): + """ + In version 3.1.0 decorator(caller) returned a nameless partial + object, thus breaking Pylons. That must not happen anymore. + >>> decorator(_memoize).__name__ + '_memoize' + """ + if __name__ == '__main__': import doctest; doctest.testmod() diff --git a/decorator/setup.py b/decorator/setup.py index 67d18e2..b406954 100644 --- a/decorator/setup.py +++ b/decorator/setup.py @@ -3,7 +3,7 @@ try: except ImportError: from distutils.core import setup -VERSION = '3.1.0' +VERSION = '3.1.1' if __name__ == '__main__': try: |