check_shapes.argument_ref

Code for (de)referencing arguments.

Module Contents

class check_shapes.argument_ref.ArgumentRef

Bases: abc.ABC

A reference to an argument.

abstract property is_result: bool

Whether this is a reference to the function result.

Return type:

bool

abstract property root_argument_name: str

Name of the argument this reference eventually starts from.

Returns RESULT_TOKEN if this in an argument to the function result.

Return type:

str

abstract get(arg_map, context)

Get the value(s) of this argument from the given argument map.

Parameters:
Return type:

Sequence[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

abstract __repr__()

Return a string representation of this reference.

Return type:

str

class check_shapes.argument_ref.RootArgumentRef

Bases: ArgumentRef

A reference to a single argument.

property is_result: bool

Whether this is a reference to the function result.

Return type:

bool

property root_argument_name: str

Name of the argument this reference eventually starts from.

Returns RESULT_TOKEN if this in an argument to the function result.

Return type:

str

get(arg_map, context)

Get the value(s) of this argument from the given argument map.

Parameters:
Return type:

Sequence[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

__repr__()

Return a string representation of this reference.

Return type:

str

class check_shapes.argument_ref.DelegatingArgumentRef

Bases: ArgumentRef

Abstract base class for ArgumentRefs that delegates to a source.

property is_result: bool

Whether this is a reference to the function result.

Return type:

bool

property root_argument_name: str

Name of the argument this reference eventually starts from.

Returns RESULT_TOKEN if this in an argument to the function result.

Return type:

str

abstract map_value(value, context)

Map this value, from self.source to new value(s).

Parameters:
Return type:

Iterable[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

map_context(context)

Pre-map this error context from self.source.

The mapped value will both be used for error messages and passed to map_value above.

Parameters:

context (check_shapes.error_contexts.ErrorContext) –

Return type:

check_shapes.error_contexts.ErrorContext

get(arg_map, context)

Get the value(s) of this argument from the given argument map.

Parameters:
Return type:

Sequence[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

class check_shapes.argument_ref.AttributeArgumentRef

Bases: DelegatingArgumentRef

A reference to an attribute on an argument.

map_value(value, context)

Map this value, from self.source to new value(s).

Parameters:
Return type:

Iterable[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

map_context(context)

Pre-map this error context from self.source.

The mapped value will both be used for error messages and passed to map_value above.

Parameters:

context (check_shapes.error_contexts.ErrorContext) –

Return type:

check_shapes.error_contexts.ErrorContext

__repr__()

Return a string representation of this reference.

Return type:

str

class check_shapes.argument_ref.IndexArgumentRef

Bases: DelegatingArgumentRef

A reference to an element in a list.

map_value(value, context)

Map this value, from self.source to new value(s).

Parameters:
Return type:

Iterable[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

map_context(context)

Pre-map this error context from self.source.

The mapped value will both be used for error messages and passed to map_value above.

Parameters:

context (check_shapes.error_contexts.ErrorContext) –

Return type:

check_shapes.error_contexts.ErrorContext

__repr__()

Return a string representation of this reference.

Return type:

str

class check_shapes.argument_ref.AllElementsRef

Bases: DelegatingArgumentRef

A reference to all elements in a collection.

map_value(value, context)

Map this value, from self.source to new value(s).

Parameters:
Return type:

Iterable[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

__repr__()

Return a string representation of this reference.

Return type:

str

class check_shapes.argument_ref.KeysRef

Bases: DelegatingArgumentRef

A reference to all keys of a mapping.

map_value(value, context)

Map this value, from self.source to new value(s).

Parameters:
Return type:

Iterable[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

__repr__()

Return a string representation of this reference.

Return type:

str

class check_shapes.argument_ref.ValuesRef

Bases: DelegatingArgumentRef

A reference to all values of a mapping.

map_value(value, context)

Map this value, from self.source to new value(s).

Parameters:
Return type:

Iterable[Tuple[Any, check_shapes.error_contexts.ErrorContext]]

__repr__()

Return a string representation of this reference.

Return type:

str