library Package

library Package

arithmetic Module

class contracts.library.arithmetic.Binary(exprs, glyph, where=None)[source]

Bases: contracts.interface.RValue

eval(context)[source]
operations = {'+': <function <lambda>>, '*': <function <lambda>>, '-': <function <lambda>>, '^': <function <lambda>>}
static parse_action(s, loc, tokens)[source]
precedence = {'+': 0, '*': 1, '-': 0, '^': 2}
class contracts.library.arithmetic.Unary(glyph, expr, where=None)[source]

Bases: contracts.interface.RValue

eval(context)[source]
operations = {'-': <function <lambda>>}
static parse_action(s, loc, tokens)[source]

array Module

class contracts.library.array.Array(shape_contract=None, elements_contract=None, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]
class contracts.library.array.Shape(length, contract, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]
class contracts.library.array.ShapeContract(dimensions, ellipsis=False, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]
contracts.library.array.my_delim_list2(what, delim)[source]
contracts.library.array.np_composite(custom_string, alternatives)[source]
contracts.library.array.np_float(s, loc, tokens)[source]
contracts.library.array.np_int(s, loc, tokens)[source]
contracts.library.array.np_uint(s, loc, tokens)[source]

array_ops Module

class contracts.library.array_ops.ArrayAnd(clauses, where=None)[source]

Bases: contracts.library.array_ops.ArrayLogical

static parse_action(string, location, tokens)[source]
test_elements(context, value)[source]
class contracts.library.array_ops.ArrayConstraint(glyph, rvalue, where=None)[source]

Bases: contracts.library.array_ops.ArrayElementsTest

Comparisons for numpy array elements. They check that the condition is respected for all the entries in the array.

constraints = {'>=': <function <lambda>>, '==': <function <lambda>>, '=': <function <lambda>>, '<=': <function <lambda>>, '!=': <function <lambda>>, '<': <function <lambda>>, '>': <function <lambda>>}
static parse_action(s, loc, tokens)[source]
test_elements(context, value)[source]

Returns either a bool or an array of bool.

class contracts.library.array_ops.ArrayElementsTest(where)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
test_elements(context, value)[source]

Returns either a bool or an array of bool.

class contracts.library.array_ops.ArrayLogical(glyph, precedence)[source]

Bases: contracts.library.array_ops.ArrayElementsTest

class contracts.library.array_ops.ArrayOR(clauses, where=None)[source]

Bases: contracts.library.array_ops.ArrayLogical

static parse_action(string, location, tokens)[source]
test_elements(context, value)[source]
class contracts.library.array_ops.ArrayORCustomString(custom_string, **other)[source]

Bases: contracts.library.array_ops.ArrayOR

class contracts.library.array_ops.DType(dtype, dtype_string=None, where=None)[source]

Bases: contracts.library.array_ops.ArrayElementsTest

Checks that the value is an array with the given dtype.

static parse_action(dtype=None)[source]
test_elements(context, value)[source]

comparison Module

class contracts.library.comparison.CheckOrder(expr1, glyph, expr2, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
conditions = {'>=': (False, True, True), '==': (False, True, False), '=': (False, True, False), '<=': (True, True, False), '!=': (True, False, True), '<': (True, False, False), '>': (False, False, True)}
static parse_action(s, loc, tokens)[source]

compositions Module

class contracts.library.compositions.And(clauses, where=None)[source]

Bases: contracts.library.compositions.Logical, contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(string, location, tokens)[source]
class contracts.library.compositions.Logical(glyph, precedence)[source]

Bases: object

class contracts.library.compositions.Not(clauses, where=None)[source]

Bases: contracts.library.compositions.Logical, contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(string, location, tokens)[source]
class contracts.library.compositions.OR(clauses, where=None)[source]

Bases: contracts.library.compositions.Logical, contracts.interface.Contract

check_contract(context, value, silent)[source]
get_error(context, value)[source]

This assumes that we are going to fail

static parse_action(string, location, tokens)[source]

dicts Module

class contracts.library.dicts.Dict(length=None, key_c=None, value_c=None, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]

dummy Module

class contracts.library.dummy.Any(where=None)[source]

Bases: contracts.interface.Contract

Always true.

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]
class contracts.library.dummy.Never(where=None)[source]

Bases: contracts.interface.Contract

A contract that does not match anything. Useful for debugging.

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]

extensions Module

class contracts.library.extensions.CheckCallable(callable)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
class contracts.library.extensions.CheckCallableWithSelf(callable)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
class contracts.library.extensions.Extension(identifier, where=None, args=(), kwargs=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]
registrar = {'Container': CheckCallable(<function f>), 'int': SeparateContext(OR([CheckType(int,'Int'), Extension('np_scalar_int'), And([Extension('np_scalar'), Array(None,ArrayOR([DType(dtype('int8'),'i1'), DType(dtype('int8')), DType(dtype('int16')), DType(dtype('int32')), DType(dtype('int64'))]))])])), 'MutableMapping': CheckCallable(<function f>), 'float': SeparateContext(OR([CheckType(float,'Float'), Extension('np_scalar_float'), And([Extension('np_scalar'), Array(None,ArrayOR([DType(dtype('float32')), DType(dtype('float64'))]))])])), 'np_zeroshape_array': CheckCallable(<function np_zeroshape_array>), 'np_scalar_uint': SeparateContext(OR([CheckType(uint8,'np_uint8'), CheckType(uint16,'np_uint16'), CheckType(uint32,'np_uint32'), CheckType(uint64,'np_uint64')])), 'Mapping': CheckCallable(<function f>), 'Callable': CheckCallable(<function f>), 'np_scalar_float': SeparateContext(OR([CheckType(float32,'np_float32'), CheckType(float64,'np_float64')])), 'finite': CheckCallable(<function finite>), 'Hashable': CheckCallable(<function f>), 'None': CheckCallable(<function is_None>), 'MutableSet': CheckCallable(<function f>), 'np_scalar_type': SeparateContext(OR([Extension('np_scalar_int'), Extension('np_scalar_uint'), Extension('np_scalar_float')])), 'MutableSequence': CheckCallable(<function f>), 'number': SeparateContext(OR([Extension('float'), Extension('int'), Extension('uint')])), 'Sized': CheckCallable(<function f>), 'uint': SeparateContext(OR([Extension('np_scalar_uint'), And([Extension('np_scalar'), Array(None,ArrayOR([DType(dtype('uint8'),'u1'), DType(dtype('uint8')), DType(dtype('uint16')), DType(dtype('uint32')), DType(dtype('uint64'))]))])])), 'Set': CheckCallable(<function f>), 'Iterator': CheckCallable(<function f>), 'Sequence': CheckCallable(<function f>), 'np_scalar': SeparateContext(OR([Extension('np_zeroshape_array'), Extension('np_scalar_type')])), 'Iterable': CheckCallable(<function f>), 'np_scalar_int': SeparateContext(OR([CheckType(int8,'np_int8'), CheckType(int16,'np_int16'), CheckType(int32,'np_int32'), CheckType(int64,'np_int64')])), 'NoneType': CheckCallable(<function is_None>)}
contracts.library.extensions.build_args_kwargs(s, loc, tokens)[source]
contracts.library.extensions.describe_callable(c)[source]
contracts.library.extensions.get_callable_module(c)[source]
contracts.library.extensions.get_callable_name(c)[source]

Get a displayable name for the callable even if __name__ is not available.

lists Module

class contracts.library.lists.List(length_contract=None, elements_contract=None, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]

map Module

class contracts.library.map.Map(length=None, key_c=None, value_c=None, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]

miscellaneous_aliases Module

contracts.library.miscellaneous_aliases.is_None(x)[source]
contracts.library.miscellaneous_aliases.ist(C)[source]
contracts.library.miscellaneous_aliases.m_new_contract(name, f)[source]

separate_context Module

class contracts.library.separate_context.SeparateContext(contract, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]

seq Module

class contracts.library.seq.Seq(length_contract=None, elements_contract=None, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]

simple_values Module

class contracts.library.simple_values.EqualTo(rvalue, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]
class contracts.library.simple_values.SimpleRValue(value, representation=None, where=None)[source]

Bases: contracts.interface.RValue

eval(context)[source]

strings Module

class contracts.library.strings.String(length=None, where=None)[source]

Bases: contracts.library.strings.StringBase

DESCRIPTION = 'an ANSI or Unicode string'
KEYWORDS = ['string']
TYPE

alias of basestring

class contracts.library.strings.AnsiString(length=None, where=None)[source]

Bases: contracts.library.strings.StringBase

DESCRIPTION = 'an ANSI string'
KEYWORDS = ['str']
TYPE

alias of str

class contracts.library.strings.UnicodeString(length=None, where=None)[source]

Bases: contracts.library.strings.StringBase

DESCRIPTION = 'a Unicode string'
KEYWORDS = ['unicode']
TYPE

alias of unicode

suggester Module

contracts.library.suggester.create_suggester(get_options, get_message=<function default_message>, pattern=None)[source]
contracts.library.suggester.default_message(identifier)[source]
contracts.library.suggester.find_best_match(s, options)[source]
contracts.library.suggester.find_longest_match(s, options)[source]
contracts.library.suggester.levenshtein(a, b)[source]

Calculates the Levenshtein distance between a and b.

contracts.library.suggester.longest_match(a, b)[source]

tuple Module

class contracts.library.tuple.Tuple(length=None, elements=None, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]

types_misc Module

class contracts.library.types_misc.CheckType(types, type_string=None, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(types)[source]
class contracts.library.types_misc.Type(type_constraint, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(s, loc, tokens)[source]

variables Module

class contracts.library.variables.BindVariable(variable, allowed_types, where=None)[source]

Bases: contracts.interface.Contract

check_contract(context, value, silent)[source]
static parse_action(allowed_types)[source]
class contracts.library.variables.VariableRef(variable, where=None)[source]

Bases: contracts.interface.RValue

eval(context)[source]
static parse_action(s, loc, tokens)[source]