module documentation

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_factory 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_wrapper 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_wrapper akin to functools.update_wrapper
Constant OLD_SYS_PATH 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.
def __call__(self, func): (source)

Undocumented

def decorator(caller): (source)

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.

def decorator_factory(cls): (source)

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.

def getattr_(obj, name, default_thunk): (source)

Similar to .setdefault in dictionaries.

def getinfo(func): (source)

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)>
@decorator
def memoize(func, *args): (source)

Undocumented

def new_wrapper(wrapper, model): (source)

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. Moreovoer, 'model' can be a dictionary with keys 'name', 'doc', 'module', 'dict', 'defaults'.

def update_wrapper(wrapper, model, infodict=None): (source)

akin to functools.update_wrapper

OLD_SYS_PATH = (source)

Undocumented

Value
sys.path[:]
def __legacysignature(signature): (source)

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.