Package harold :: Module callabletools
[show private | hide private]
[frames | no frames]

Module harold.callabletools

Useful functions and classes for handling callables.

NB: those functions are unable to manage built-in methods (so called
    method-wrappers). Unless specified otherwise, they will raise a
    C{TypeError} whenever passed such a callable.

@var  UNBOUNDED: returned by L{max_args} for callable accepting an arbitrary
                 number of arguments. UNBOUNDED is comparable to any integer,
                 and of course always considered greater. Also, most arithmetic
                 operations involving UNBOUNDED will return UNBOUNDED (all
                 except substracting, and dividing/modulo by UNBOUNDED, which
                 are not defined).

Classes
CallableWrapper Base class for wrapping callables.

Function Summary
function get_func(a_callable)
Return the function executed when the given callable is called.
  kw_args(a_callable)
Return whether the given callable accepts arbitrary keyword arguments.
int or UNBOUNDED max_args(a_callable)
Return the maximum number of arguments accepted by the given callable.
int min_args(a_callable)
Return the minimum number of arguments accepted by the given callable.
  nblines(obj)
Return the number of lines of the given function.
  signature(a_callable, include_func)
Return the signature of the given callable.

Variable Summary
_Unbounded UNBOUNDED = UNBOUNDED

Function Details

get_func(a_callable)

Return the function executed when the given callable is called.

NB: if a_callable is a class, __init__ is returned.
Parameters:
a_callable - a callable
Returns:
the function executed by a_callable
           (type=function)

kw_args(a_callable)

Return whether the given callable accepts arbitrary keyword arguments.
Parameters:
a_callable - a callable

max_args(a_callable)

Return the maximum number of arguments accepted by the given callable.
Parameters:
a_callable - a callable
Returns:
the maximum number of arguments accepted by a_callable
           (type=int or UNBOUNDED)

min_args(a_callable)

Return the minimum number of arguments accepted by the given callable.
Parameters:
a_callable - a callable
Returns:
the minimum number of arguments accepted by a_callable
           (type=int)

nblines(obj)

Return the number of lines of the given function.
Parameters:
obj - a function or code object

signature(a_callable, include_func=False)

Return the signature of the given callable.

The signature is a triple (min,max,kw) where:
  • min is the minimum number of arguments accepted by the callable
  • max is the maximum number of arguments accepted by the callable, -1 if unbounded
  • kw is a boolean indicating whether the callable accepts
If include_func is true, a 4th element, the function returned by get_func for a_callable, is included.

Variable Details

UNBOUNDED

Type:
_Unbounded
Value:
UNBOUNDED                                                              

Generated by Epydoc 2.1 on Mon Dec 18 15:25:58 2006 http://epydoc.sf.net