pitchtypes.basetypes.Converters

class pitchtypes.basetypes.Converters

Bases: object

__init__()

Methods

__init__()

convert(obj, to_type)

get_converter(from_type[, to_type])

register_converter(from_type, to_type, conv_func)

Register a converter from from_type to other type.

__weakref__

list of weak references to the object (if defined)

static register_converter(from_type, to_type, conv_func, overwrite_explicit_converters=False, overwrite_implicit_converters=False, create_implicit_converters=False)

Register a converter from from_type to other type. The converter function should be function taking as its single argument an from_type object and returning an other_type object. :type to_type: :param to_type: other type derived from AbstractBase, which the converter function converts to :type conv_func: :param conv_func: converter function from from_type to other_type :type overwrite_explicit_converters: :param overwrite_explicit_converters: can be True, False, or None (default); if True and there exists an explicit converter (i.e. the list of converter functions is of length 1), replace it by this converter function; if False raise a ValueError if an explicit converter exists :type overwrite_implicit_converters: :param overwrite_implicit_converters: if there exists an implicit converter (i.e. the list of converter functions is of length greater than 1) replace it by this converter function :type create_implicit_converters: :param create_implicit_converters: if there is an (explicit or implicit) converter from type X to type from_type, add an implicit converter from type X to other_type by extending the list of converter functions from X to from_type by this converter function; if there already exists an (explicit or implicit) converter from X to other_type, it will not be overwritten