pytilities.overloading.overloader

class pytilities.overloading.overloader.Overloader(overloads, add_self=True)

A collection of Overload‘s that can process calls.

Tool for overloading operations.

Has an ordered collection of overloads which serve as rules, the operation of the matching overload is called. If none match, an assertion error is raised.

__init__(overloads, add_self=True)

Construct an Overloader.

Parameters:

overloads :: (Overload...)
a collection of rules indicating which operation to call for which combination of arguments/parameters. Note: the order can effect which overload is matched as the first matching overload is used. Must specify at least one overload.
add_self :: bool = True
if True, a “self” parameter is inserted at the beginning of the parameter list of each overload
process_args()

Process given args and keyword args.

Return the callable that would be called and the args it’d receive.

Parameters:
  • args – arguments of the call
  • kwargs – keyword arguments of the call
Returns:

(processed_args, callable).

Return type:

({string: object}, callable)

process_call()

Process a call with given args and keyword args.

The matching overload is called.

Parameters:
  • args – arguments of the call
  • kwargs – keyword arguments of the call
Returns:

the return value of the called operation

__weakref__

list of weak references to the object (if defined)

Previous topic

pytilities.overloading.overload

Next topic

pytilities.overloading.parameter

This Page