Decorator module by Michele Simionato <michelesimionato@libero.it> Copyright Michele Simionato, distributed under the terms of the BSD License (see below). http://www.phyast.pitt.edu/~micheles/python/documentation.html
Included in NLTK for its support of a nice memoization decorator.
Function | __call__ |
Undocumented |
Function | decorator |
General purpose decorator factory: takes a caller function as input and returns a decorator with the same attributes. A caller function is any function like this: |
Function | decorator |
Take a class with a .caller method and return a callable decorator object. It works by adding a suitable __call__ method to the class; it raises a TypeError if the class already has a nontrivial __call__ method. |
Function | getattr_ |
Similar to .setdefault in dictionaries. |
Function | getinfo |
Returns an info dictionary containing: - name (the name of the function : str) - argnames (the names of the arguments : list) - defaults (the values of the default arguments : tuple) - signature (the signature : str) - fullsignature (the full signature : Signature) - doc (the docstring : str) - module (the module name : str) - dict (the function __dict__ : str)... |
Function | memoize |
Undocumented |
Function | new |
An improvement over functools.update_wrapper. The wrapper is a generic callable object. It works by generating a copy of the wrapper with the right signature and by updating the copy, not the original. ... |
Function | update |
akin to functools.update_wrapper |
Constant | OLD |
Undocumented |
Function | __legacysignature |
For retrocompatibility reasons, we don't use a standard Signature. Instead, we use the string generated by this method. Basically, from a Signature we create a string and remove the default values. |
General purpose decorator factory: takes a caller function as input and returns a decorator with the same attributes. A caller function is any function like this:
def caller(func, *args, **kw): # do something return func(*args, **kw)
Here is an example of usage:
>>> @decorator ... def chatty(f, *args, **kw): ... print("Calling %r" % f.__name__) ... return f(*args, **kw)
>>> chatty.__name__ 'chatty'
>>> @chatty ... def f(): pass ... >>> f() Calling 'f'
decorator can also take in input a class with a .caller method; in this case it converts the class into a factory of callable decorator objects. See the documentation for an example.
Take a class with a .caller method and return a callable decorator object. It works by adding a suitable __call__ method to the class; it raises a TypeError if the class already has a nontrivial __call__ method.
Returns an info dictionary containing: - name (the name of the function : str) - argnames (the names of the arguments : list) - defaults (the values of the default arguments : tuple) - signature (the signature : str) - fullsignature (the full signature : Signature) - doc (the docstring : str) - module (the module name : str) - dict (the function __dict__ : str)
>>> def f(self, x=1, y=2, *args, **kw): pass
>>> info = getinfo(f)
>>> info["name"] 'f' >>> info["argnames"] ['self', 'x', 'y', 'args', 'kw']
>>> info["defaults"] (1, 2)
>>> info["signature"] 'self, x, y, *args, **kw'
>>> info["fullsignature"] <Signature (self, x=1, y=2, *args, **kw)>