States (objetto.states)

Immutable state types.

class objetto.states.DictState(initial=())

Immutable dictionary state.

Inherits from:
Parameters

initial (collections.abc.Mapping or collections.abc.Iterable[tuple[collections.abc.Hashable, Any]]) – Initial values.

__hash__()

Get hash.

Returns

Hash.

Return type

int

__eq__(other)

Compare for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

__contains__(key)

Get whether key is present.

Parameters

key (collections.abc.Hashable) – Key.

Returns

True if contains.

Return type

bool

__iter__()

Iterate over keys.

Returns

Keys iterator.

Return type

collections.abc.Iterator[collections.abc.Hashable]

__len__()

Get key count.

Returns

Key count.

Return type

int

__repr__()

Get representation.

Returns

Representation.

Return type

str

__reversed__()

Iterate over reversed keys.

Returns

Reversed keys iterator.

Return type

collections.abc.Iterator[collections.abc.Hashable]

__getitem__(key)

Get value for key.

Parameters

key (collections.abc.Hashable) – Key.

Returns

Value.

Raises

KeyError – Key is not present.

_clear()

Clear.

Returns

Transformed.

Return type

objetto.states.DictState

_discard(key)

Discard key if it exists.

Parameters

key (collections.abc.Hashable) – Key.

Returns

Transformed.

Return type

objetto.states.DictState

_remove(key)

Delete existing key.

Parameters

key (collections.abc.Hashable) – Key.

Returns

Transformed.

Return type

objetto.states.DictState

Raises

KeyError – Key is not present.

_set(key, value)

Set value for key.

Parameters
Returns

Transformed.

Return type

objetto.states.DictState

_update(*args, **kwargs)

Update keys and values. Same parameters as dict.update().

Returns

Transformed.

Return type

objetto.states.DictState

get(key, fallback=None)

Get value for key, return fallback value if key is not present.

Parameters
Returns

Value or fallback value.

iteritems()

Iterate over items.

Returns

Items iterator.

Return type

collections.abc.Iterator[tuple[collections.abc.Hashable, Any]]

iterkeys()

Iterate over keys.

Returns

Keys iterator.

Return type

collections.abc.Iterator[collections.abc.Hashable]

itervalues()

Iterate over values.

Returns

Values iterator.

Return type

collections.abc.Iterator

find_with_attributes(**attributes)

Find first value that matches unique attribute values.

Parameters

attributes – Attributes to match.

Returns

Value that has matching attributes.

Raises

ValueError – No attributes provided or no match found.

class objetto.states.ListState(initial=())

Immutable list state.

Inherits from:
Parameters

initial (collections.abc.Iterable) – Initial values.

__hash__()

Get hash.

Returns

Hash.

Return type

int

__eq__(other)

Compare for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

__contains__(value)

Get whether value is present.

Parameters

value – Value.

Returns

True if contains.

Return type

bool

__iter__()

Iterate over values.

Returns

Values iterator.

Return type

collections.abc.Iterator

__len__()

Get value count.

Returns

Value count.

Return type

int

__repr__()

Get representation.

Returns

Representation.

Return type

str

__reversed__()

Iterate over reversed values.

Returns

Reversed values iterator.

Return type

collections.abc.Iterator

__getitem__(index)

Get value/values at index/from slice.

Parameters

index (int or slice) – Index/slice.

Returns

Value/values.

Return type

Any or objetto.states.ListState

_clear()

Clear.

Returns

Transformed.

Return type

objetto.states.ListState

_insert(index, *values)

Insert value(s) at index.

Parameters
  • index (int) – Index.

  • values – Value(s).

Returns

Transformed.

Return type

objetto.states.ListState

Raises

ValueError – No values provided.

_append(value)

Append value at the end.

Parameters

value – Value.

Returns

Transformed.

Return type

objetto.states.ListState

_extend(iterable)

Extend at the end with iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Transformed.

Return type

objetto.states.ListState

_remove(value)

Remove first occurrence of value.

Parameters

value – Value.

Returns

Transformed.

Return type

objetto.states.ListState

Raises

ValueError – Value is not present.

_reverse()

Reverse values.

Returns

Transformed.

Return type

objetto.states.ListState

_move(item, target_index)

Move values internally.

Parameters
  • item (int or slice) – Index/slice.

  • target_index (int) – Target index.

Returns

Transformed.

Return type

objetto.states.ListState

_delete(item)

Delete values at index/slice.

Parameters

item (int or slice) – Index/slice.

Returns

Transformed.

Return type

objetto.states.ListState

_update(index, *values)

Update value(s) starting at index.

Parameters
  • index (int) – Index.

  • values – Value(s).

Returns

Transformed.

Return type

objetto.states.ListState

Raises

ValueError – No values provided.

count(value)

Count number of occurrences of a value.

Parameters

value – Value.

Returns

Number of occurrences.

Return type

int

index(value, start=None, stop=None)

Get index of a value.

Parameters
  • value – Value.

  • start (int or None) – Start index.

  • stop (int or None) – Stop index.

Returns

Index of value.

Return type

int

Raises

ValueError – Provided stop but did not provide start.

resolve_index(index, clamp=False)

Resolve index to a positive number.

Parameters
  • index (int) – Input index.

  • clamp (bool) – Whether to clamp between zero and the length.

Returns

Resolved index.

Return type

int

Raises

IndexError – Index out of range.

resolve_continuous_slice(slc)

Resolve continuous slice according to length.

Parameters

slc (slice) – Continuous slice.

Returns

Index and stop.

Return type

tuple[int, int]

Raises

IndexError – Slice is noncontinuous.

find_with_attributes(**attributes)

Find first value that matches unique attribute values.

Parameters

attributes – Attributes to match.

Returns

Value that has matching attributes.

Raises

ValueError – No attributes provided or no match found.

class objetto.states.SetState(initial=())

Immutable set state.

Inherits from:
Parameters

initial (collections.abc.Iterable) – Initial values.

classmethod _from_iterable(iterable)

Make set state from iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Set state.

Return type

objetto.states.SetState

__hash__()

Get hash.

Returns

Hash.

Return type

int

__eq__(other)

Compare for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

__contains__(value)

Get whether value is present.

Parameters

value (collections.abc.Hashable) – Value.

Returns

True if contains.

Return type

bool

__iter__()

Iterate over values.

Returns

Values iterator.

Return type

collections.abc.Iterator[collections.abc.Hashable]

__len__()

Get value count.

Returns

Value count.

Return type

int

__repr__()

Get representation.

Returns

Representation.

Return type

str

_hash()

Get hash.

Returns

Hash.

Return type

int

_clear()

Clear.

Returns

Transformed.

Return type

objetto.states.SetState

_add(value)

Add value.

Parameters

value (collections.abc.Hashable) – Value.

Returns

Transformed.

Return type

objetto.states.SetState

_discard(*values)

Discard value(s).

Parameters

values (collections.abc.Hashable) – Value(s).

Returns

Transformed.

Return type

objetto.states.SetState

Raises

ValueError – No values provided.

_remove(*values)

Remove existing value(s).

Parameters

values (collections.abc.Hashable) – Value(s).

Returns

Transformed.

Return type

objetto.states.SetState

Raises
_replace(old_value, new_value)

Replace existing value with a new one.

Parameters
Returns

Transformed.

Return type

objetto.states.SetState

Raises

KeyError – Value is not present.

_update(iterable)

Update with iterable.

Parameters

iterable (collections.abc.Iterable[collections.abc.Hashable]) – Iterable.

Returns

Transformed.

Return type

objetto.states.SetState

isdisjoint(iterable)

Get whether is a disjoint set of an iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

True if is disjoint.

Return type

bool

issubset(iterable)

Get whether is a subset of an iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

True if is subset.

Return type

bool

issuperset(iterable)

Get whether is a superset of an iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

True if is superset.

Return type

bool

intersection(iterable)

Get intersection.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Intersection.

Return type

objetto.states.SetState

difference(iterable)

Get difference.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Difference.

Return type

objetto.states.SetState

inverse_difference(iterable)

Get an iterable’s difference to this.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Inverse Difference.

Return type

objetto.states.SetState

symmetric_difference(iterable)

Get symmetric difference.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Symmetric difference.

Return type

objetto.states.SetState

union(iterable)

Get union.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Union.

Return type

objetto.states.SetState

find_with_attributes(**attributes)

Find first value that matches unique attribute values.

Parameters

attributes – Attributes to match.

Returns

Value that has matching attributes.

Raises

ValueError – No attributes provided or no match found.