Bases (objetto.bases)

Base types.

Base Classes

class objetto.bases.BaseMeta(name, bases, dct)

Metaclass for objetto.bases.Base.

Inherits from:
Inherited by:
Features:
  • Forces the use of __slots__.

  • Forces __hash__ to be declared if __eq__ was declared.

  • Decorates __init__ methods to update the initializing tag.

  • Prevents base class attributes from changing.

  • Runtime checking for final decorated classes/methods.

  • Implements __fullname__ class property for backporting qualified name.

__repr__()

Get class representation.

Returns

Class representation.

Return type

str

__dir__()

Get a simplified list of class member names.

Returns

List of class member names.

Return type

list[str]

final __setattr__(name, value)

Prevent setting read-only class attributes.

Parameters
  • name – Name.

  • value – Value.

Str name

str

Raises

AttributeError – Read-only attribute.

final __delattr__(name)

Prevent deleting read-only class attributes.

Parameters

name (str) – Name.

Raises

AttributeError – Read-only attribute.

property __fullname__

Get qualified class name if possible, fall back to class name otherwise.

Returns

Full class name.

Return type

str

class objetto.bases.Base

Base class for all Objetto types.

Metaclass:
Inherits from:
Inherited By:
Features:
  • Forces the use of __slots__.

  • Forces __hash__ to be declared if __eq__ was declared.

  • Property that tells whether instance is initializing or not.

  • Default implementation of __copy__ raises an error.

  • Default implementation of __ne__ returns the opposite of __eq__.

  • Prevents base class attributes from changing.

  • Runtime checking for final decorated classes/methods.

  • Simplified __dir__ result that shows only relevant members for client code.

  • Implements __fullname__ class property for backporting qualified name.

__copy__()

Prevents shallow copy by default.

Raises

RuntimeError – Always raised.

__repr__()

Get representation using class’ full name if possible.

Returns

Representation.

Return type

str

__ne__(other)

Compare for inequality by negating the result of __eq__. This is a backport of the default python 3 behavior to python 2.

Parameters

other – Another object.

Returns

True if not equal.

Return type

bool or NotImplemented

__dir__()

Get a simplified list of member names.

Returns

List of member names.

Return type

list[str]

property _initializing

Whether __init__ (or any other initialization method) is running.

Return type

bool

class objetto.bases.BaseHashable

Base hashable.

Inherits from:
Inherited By:
Features:
  • Forces implementation of __hash__ method.

abstract __hash__()

Get hash.

Returns

Hash.

Return type

int

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseSized

Base sized.

Inherits from:
Inherited By:
Features:
  • Has a length (count).

abstract __len__()

Get count.

Returns

Count.

Return type

int

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseIterable

Base iterable.

Inherits from:
Inherited By:
Features:
  • Can be iterated over.

abstract __iter__()

Iterate over.

Returns

Iterator.

Return type

collections.abc.Iterator

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseContainer

Base container.

Inherits from:
Inherited By:
Features:
  • Contains values.

abstract __contains__(content)

Get whether content is present.

Parameters

content – Content.

Returns

True if contains.

Return type

bool

Raises

NotImplementedError – Abstract method not implemented.

Base Decorators

@objetto.bases.final

Decorator based on typing.final() that enables runtime checking for objetto.bases.Base classes.

>>> from objetto.bases import Base, final

>>> @final
... class FinalClass(Base):  # final class
...     pass
...
>>> class Class(Base):
...     @final
...     def final_method(self):  # final method
...         pass
...
Parameters

obj (function or type) – Method function or class.

Returns

Decorated method function or class.

Return type

function or type

@objetto.bases.init

Method decorator that sets the initializing tag for objetto.bases.Base objects.

>>> from objetto.bases import init

>>> class MyClass(Base):
...     def __init__(self):  # initialization tag is implicitly set
...         print(("__init__", self._initializing))
...
...     @init
...     def init(self):
...         print(("init", self._initializing))
...
...     def not_init(self):
...         print(("not_init", self._initializing))
...
>>> my_obj = MyClass()
('__init__', True)
>>> my_obj.init()
('init', True)
>>> my_obj.not_init()
('not_init', False)
Parameters

func (function) – Method function.

Returns

Decorated method function.

Return type

function

Base Functions

objetto.bases.simplify_member_names(names)

Iterate over member names and only yield the simplified ones.

Parameters

names (str) – Input names.

Returns

Simplified names iterator.

Return type

collections.abc.Iterator[str]

objetto.bases.make_base_cls(base=None, qual_name=None, module=None, dct=None)

Make a subclass of objetto.bases.Base on the fly.

Parameters
  • base (type[objetto.bases.Base]) – Base class.

  • qual_name (str or None) – Qualified name.

  • module (str or None) – Module.

  • dct – Members dictionary.

  • dct – dict[str, Any] or None

Returns

Generated subclass.

Return type

type[objetto.bases.Base]

Base Context Managers

objetto.bases.init_context(obj, flag=True)

Context manager that sets the initializing tag for objetto.bases.Base objects.

>>> from objetto.bases import init_context

>>> class MyClass(Base):
...     def __init__(self):  # initialization tag is implicitly set
...         print(("__init__", self._initializing))
...
...     def init(self):
...         with init_context(self):
...             print(("init (inside of context)", self._initializing))
...         print(("init (outside of context)", self._initializing))
...
>>> my_obj = MyClass()
('__init__', True)
>>> my_obj.init()
('init (inside of context)', True)
('init (outside of context)', False)
Parameters
Returns

Context manager.

Return type

contextlib.AbstractContextManager

Base Abstract Member

objetto.bases.abstract_member(types=())

Used to indicate an abstract attribute member in a class.

>>> from objetto.bases import Base, abstract_member

>>> class AbstractClass(Base):
...     some_attribute = abstract_member(int)  # will prevent instatiation
...
>>> obj = AbstractClass()
Traceback (most recent call last):
TypeError: Can't instantiate abstract class AbstractClass with abstract method...

>>> class ConcreteClass(AbstractClass):
...     some_attribute = 3  # concrete
>>> obj = ConcreteClass()
Parameters

types (type or tuple[type]) – Type(s) for static type checking.

Returns

Abstract member.

Return type

type[objetto.bases.AbstractMember]

Base Collection Classes

class objetto.bases.BaseCollection

Base collection.

Inherits from:
Inherited By:
Features:
  • Method to find content that matches attribute values.

abstract find_with_attributes(**attributes)

Find first value that matches unique attribute values.

Parameters

attributes – Attributes to match.

Returns

Value that has matching attributes.

Raises
class objetto.bases.BaseProtectedCollection

Base protected collection.

Inherits from:
Inherited By:
Features:
  • Has protected transformation methods.

  • Transformations return a transformed version (immutable) or self (mutable).

abstract _clear()

Clear.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedCollection

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseInteractiveCollection

Base interactive collection.

Inherits from:
Inherited By:
Features:
  • Has public transformation methods.

  • Transformations return a transformed version (immutable) or self (mutable).

final clear()

Clear.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveCollection

class objetto.bases.BaseMutableCollection

Base mutable collection.

Inherits from:
Inherited By:
Features:
  • Has public mutable transformation and magic methods.

clear()

Clear.

Base Dictionary Classes

class objetto.bases.BaseDict

Base dictionary collection.

Inherits from:
Inherited By:
abstract __eq__(other)

Compare for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

Raises

NotImplementedError – Abstract method not implemented.

abstract __reversed__()

Iterate over reversed keys.

Returns

Reversed keys iterator.

Return type

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

Raises

NotImplementedError – Abstract method not implemented.

abstract __getitem__(key)

Get value for key.

Parameters

key (collections.abc.Hashable) – Key.

Returns

Value.

Raises
abstract get(key, fallback=None)

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

Parameters
Returns

Value or fallback value.

Raises

NotImplementedError – Abstract method not implemented.

abstract iteritems()

Iterate over items.

Returns

Items iterator.

Return type

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

Raises

NotImplementedError – Abstract method not implemented.

abstract iterkeys()

Iterate over keys.

Returns

Keys iterator.

Return type

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

Raises

NotImplementedError – Abstract method not implemented.

abstract itervalues()

Iterate over values.

Returns

Values iterator.

Return type

collections.abc.Iterator

Raises

NotImplementedError – Abstract method not implemented.

items()

Get items.

Returns

Items.

Return type

collections.abc.ItemsView

keys()

Get keys.

Returns

Keys.

Return type

collections.abc.KeysView

values()

Get values.

Returns

Values.

Return type

collections.abc.ValuesView

class objetto.bases.BaseProtectedDict

Base protected dictionary collection.

Inherits from:
Inherited By:
abstract _discard(key)

Discard key if it exists.

Parameters

key (collections.abc.Hashable) – Key.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedDict

Raises

NotImplementedError – Abstract method not implemented.

abstract _remove(key)

Delete existing key.

Parameters

key (collections.abc.Hashable) – Key.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedDict

Raises
abstract _set(key, value)

Set value for key.

Parameters
Returns

Transformed.

Return type

objetto.bases.BaseProtectedDict

Raises

NotImplementedError – Abstract method not implemented.

abstract _update(*args, **kwargs)

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

Returns

Transformed.

Return type

objetto.bases.BaseProtectedDict

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseInteractiveDict

Base interactive dictionary collection.

Inherits from:
Inherited By:
discard(key)

Discard key if it exists.

Parameters

key (collections.abc.Hashable) – Key.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveDict

remove(key)

Delete existing key.

Parameters

key (collections.abc.Hashable) – Key.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveDict

Raises

KeyError – Key is not present.

set(key, value)

Set value for key.

Parameters
Returns

Transformed.

Return type

objetto.bases.BaseInteractiveDict

update(*args, **kwargs)

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

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveDict

class objetto.bases.BaseMutableDict

Base mutable dictionary collection.

Inherits from:
Inherited By:
__setitem__(key, value)

Set value for key.

Parameters
__delitem__(key)

Delete key.

Parameters

key (collections.abc.Hashable) – Key.

Raises

KeyError – Key is not preset.

clear()

Clear.

abstract pop(key, fallback=<objetto._bases.bases.MISSING object>)

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

Parameters
Returns

Value or fallback value.

Raises
abstract popitem()

Get item and discard key.

Returns

Item.

Return type

tuple[collections.abc.Hashable, Any]

Raises
abstract setdefault(key, default=None)

Get the value for the specified key, insert key with default if not present.

Parameters
Returns

Existing or default value.

Raises

NotImplementedError – Abstract method not implemented.

discard(key)

Discard key if it exists.

Parameters

key (collections.abc.Hashable) – Key.

remove(key)

Delete existing key.

Parameters

key (collections.abc.Hashable) – Key.

Raises

KeyError – Key is not present.

set(key, value)

Set value for key.

Parameters
update(*args, **kwargs)

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

Base List Classes

class objetto.bases.BaseList

Base list collection.

Inherits from:
Inherited By:
abstract __eq__(other)

Compare for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

Raises

NotImplementedError – Abstract method not implemented.

abstract __reversed__()

Iterate over reversed values.

Returns

Reversed values iterator.

Return type

collections.abc.Iterator

Raises

NotImplementedError – Abstract method not implemented.

abstract __getitem__(index)

Get value/values at index/from slice.

Parameters

index (int or slice) – Index/slice.

Returns

Value/values.

Return type

Any or tuple[Any]

Raises

NotImplementedError – Abstract method not implemented.

abstract count(value)

Count number of occurrences of a value.

Parameters

value – Value.

Returns

Number of occurrences.

Return type

int

Raises

NotImplementedError – Abstract method not implemented.

abstract 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
abstract 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
abstract 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
class objetto.bases.BaseProtectedList

Base protected list collection.

Inherits from:
Inherited By:
abstract _insert(index, *values)

Insert value(s) at index.

Parameters
  • index (int) – Index.

  • values – Value(s).

Returns

Transformed.

Return type

objetto.bases.BaseProtectedList

Raises
abstract _append(value)

Append value at the end.

Parameters

value – Value.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedList

Raises

NotImplementedError – Abstract method not implemented.

abstract _extend(iterable)

Extend at the end with iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedList

Raises

NotImplementedError – Abstract method not implemented.

abstract _remove(value)

Remove first occurrence of value.

Parameters

value – Value.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedList

Raises
abstract _reverse()

Reverse values.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedList

Raises

NotImplementedError – Abstract method not implemented.

abstract _move(item, target_index)

Move values internally.

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

  • target_index (int) – Target index.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedList

Raises

NotImplementedError – Abstract method not implemented.

abstract _delete(item)

Delete values at index/slice.

Parameters

item (int or slice) – Index/slice.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedList

Raises

NotImplementedError – Abstract method not implemented.

abstract _update(index, *values)

Update value(s) starting at index.

Parameters
  • index (int) – Index.

  • values – Value(s).

Returns

Transformed.

Return type

objetto.bases.BaseProtectedList

Raises
class objetto.bases.BaseInteractiveList

Base interactive list collection.

Inherits from:
Inherited By:
insert(index, *values)

Insert value(s) at index.

Parameters
  • index (int) – Index.

  • values – Value(s).

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveList

Raises

ValueError – No values provided.

append(value)

Append value at the end.

Parameters

value – Value.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveList

extend(iterable)

Extend at the end with iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveList

remove(value)

Remove first occurrence of value.

Parameters

value – Value.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveList

Raises

ValueError – Value is not present.

reverse()

Reverse values.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveList

move(item, target_index)

Move values internally.

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

  • target_index (int) – Target index.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveList

delete(item)

Delete values at index/slice.

Parameters

item (int or slice) – Index/slice.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveList

update(index, *values)

Update value(s) starting at index.

Parameters
  • index (int) – Index.

  • values – Value(s).

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveList

Raises

ValueError – No values provided.

class objetto.bases.BaseMutableList

Base mutable list collection.

Inherits from:
Inherited By:
__iadd__(iterable)

In place addition.

Parameters

iterable (collections.abc.Iterable) – Another iterable.

Returns

Added list.

Return type

objetto.bases.BaseMutableList

abstract __getitem__(index)

Get value/values at index/from slice.

Parameters

index (int or slice) – Index/slice.

Returns

Value/values.

Raises

NotImplementedError – Abstract method not implemented.

abstract __setitem__(item, value)

Set value/values at index/slice.

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

  • value – Value/values.

Raises
abstract __delitem__(item)

Delete value/values at index/slice.

Parameters

item (int or slice) – Index/slice.

Raises
abstract pop(index=- 1)

Pop value from index.

Parameters

index (int) – Index.

Returns

Value.

Raises

NotImplementedError – Abstract method not implemented.

clear()

Clear.

insert(index, *values)

Insert value(s) at index.

Parameters
  • index (int) – Index.

  • values – Value(s).

Raises

ValueError – No values provided.

append(value)

Append value at the end.

Parameters

value – Value.

extend(iterable)

Extend at the end with iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

remove(value)

Remove first occurrence of value.

Parameters

value – Value.

Raises

ValueError – Value is not present.

reverse()

Reverse values.

move(item, target_index)

Move values internally.

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

  • target_index (int) – Target index.

delete(item)

Delete values at index/slice.

Parameters

item (int or slice) – Index/slice.

update(index, *values)

Update value(s) starting at index.

Parameters
  • index (int) – Index.

  • values – Value(s).

Raises

ValueError – No values provided.

Base Set Classes

class objetto.bases.BaseSet

Base set collection.

Inherits from:
Inherited By:
__le__(other)

Less equal operator (self <= other).

Parameters

other (collections.abc.Set) – Another set or any object.

Returns

True if considered less equal.

Return type

bool

__lt__(other)

Less than operator: self < other.

Parameters

other (collections.abc.Set) – Another set or any object.

Returns

True if considered less than.

Return type

bool

__gt__(other)

Greater than operator: self > other.

Parameters

other (collections.abc.Set) – Another set or any object.

Returns

True if considered greater than.

Return type

bool

__ge__(other)

Greater equal operator: self >= other.

Parameters

other (collections.abc.Set) – Another set or any object.

Returns

True if considered greater equal.

Return type

bool

__and__(other)

Get intersection: self & other.

Parameters

other (collections.abc.Iterable) – Iterable or any other object.

Returns

Intersection or NotImplemented if not an iterable.

Return type

objetto.bases.BaseSet

__rand__(other)

Get intersection: other & self.

Parameters

other (collections.abc.Iterable) – Iterable or any other object.

Returns

Intersection or NotImplemented if not an iterable.

Return type

objetto.bases.BaseSet

__sub__(other)

Get difference: self - other.

Parameters

other (collections.abc.Iterable) – Iterable or any other object.

Returns

Difference or NotImplemented if not an iterable.

Return type

objetto.bases.BaseSet

__rsub__(other)

Get inverse difference: other - self.

Parameters

other (collections.abc.Iterable) – Iterable or any other object.

Returns

Inverse difference or NotImplemented if not an iterable.

Return type

objetto.bases.BaseSet

__or__(other)

Get union: self | other.

Parameters

other (collections.abc.Iterable) – Iterable or any other object.

Returns

Union or NotImplemented if not an iterable.

Return type

objetto.bases.BaseSet

__ror__(other)

Get union: other | self.

Parameters

other (collections.abc.Iterable) – Iterable or any other object.

Returns

Union or NotImplemented if not an iterable.

Return type

objetto.bases.BaseSet

__xor__(other)

Get symmetric difference: self ^ other.

Parameters

other (collections.abc.Iterable) – Iterable or any other object.

Returns

Symmetric difference or NotImplemented if not an iterable.

Return type

objetto.bases.BaseSet

__rxor__(other)

Get symmetric difference: other ^ self.

Parameters

other (collections.abc.Iterable) – Iterable or any other object.

Returns

Symmetric difference or NotImplemented if not an iterable.

Return type

objetto.bases.BaseSet

abstract __eq__(other)

Compare for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

Raises

NotImplementedError – Abstract method not implemented.

abstract classmethod _from_iterable(iterable)

Make set from iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Set.

Raises

NotImplementedError – Abstract method not implemented.

abstract _hash()

Get hash.

Returns

Hash.

Return type

int

Raises

NotImplementedError – Abstract method not implemented.

abstract 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

Raises

NotImplementedError – Abstract method not implemented.

abstract issubset(iterable)

Get whether is a subset of an iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

True if is subset.

Return type

bool

Raises

NotImplementedError – Abstract method not implemented.

abstract issuperset(iterable)

Get whether is a superset of an iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

True if is superset.

Return type

bool

Raises

NotImplementedError – Abstract method not implemented.

abstract intersection(iterable)

Get intersection.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Intersection.

Return type

objetto.bases.BaseSet

Raises

NotImplementedError – Abstract method not implemented.

abstract symmetric_difference(iterable)

Get symmetric difference.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Symmetric difference.

Return type

objetto.bases.BaseSet

Raises

NotImplementedError – Abstract method not implemented.

abstract union(iterable)

Get union.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Union.

Return type

objetto.bases.BaseSet

Raises

NotImplementedError – Abstract method not implemented.

abstract difference(iterable)

Get difference.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Difference.

Return type

objetto.bases.BaseSet

Raises

NotImplementedError – Abstract method not implemented.

abstract inverse_difference(iterable)

Get an iterable’s difference to this.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Inverse Difference.

Return type

objetto.bases.BaseSet

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseProtectedSet

Base protected set collection.

Inherits from:
Inherited By:
abstract _add(value)

Add value.

Parameters

value – Value.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedSet

Raises

NotImplementedError – Abstract method not implemented.

abstract _discard(*values)

Discard value(s).

Parameters

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

Returns

Transformed.

Return type

objetto.bases.BaseProtectedSet

Raises
abstract _remove(*values)

Remove existing value(s).

Parameters

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

Returns

Transformed.

Return type

objetto.bases.BaseProtectedSet

Raises
abstract _replace(old_value, new_value)

Replace existing value with a new one.

Parameters
  • old_value – Existing value.

  • new_value – New value.

Returns

Transformed.

Return type

objetto.bases.BaseProtectedSet

Raises
abstract _update(iterable)

Update with iterable.

Parameters

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

Returns

Transformed.

Return type

objetto.bases.BaseProtectedSet

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseInteractiveSet

Base interactive set collection.

Inherits from:
Inherited By:
add(value)

Add value.

Parameters

value – Value.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveSet

discard(*values)

Discard value(s).

Parameters

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

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveSet

Raises

ValueError – No values provided.

remove(*values)

Remove existing value(s).

Parameters

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

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveSet

Raises
replace(old_value, new_value)

Replace existing value with a new one.

Parameters
  • old_value – Existing value.

  • new_value – New value.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveSet

Raises

KeyError – Old value is not present.

update(iterable)

Update with iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveSet

class objetto.bases.BaseMutableSet

Base mutable set collection.

Inherits from:
Inherited By:
__iand__(iterable)

Intersect in place: self &= iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

This mutable set.

Return type

objetto.bases.BaseMutableSet

__isub__(iterable)

Difference in place: self -= iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

This mutable set.

Return type

objetto.bases.BaseMutableSet

__ior__(iterable)

Update in place: self |= iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

This mutable set.

Return type

objetto.bases.BaseMutableSet

__ixor__(iterable)

Symmetric difference in place: self ^= iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Returns

This mutable set.

Return type

objetto.bases.BaseMutableSet

abstract pop()

Pop value.

Returns

Value.

Raises
abstract intersection_update(iterable)

Intersect.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Raises

NotImplementedError – Abstract method not implemented.

abstract symmetric_difference_update(iterable)

Symmetric difference.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Raises

NotImplementedError – Abstract method not implemented.

abstract difference_update(iterable)

Difference.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Raises

NotImplementedError – Abstract method not implemented.

clear()

Clear.

add(value)

Add value.

Parameters

value – Value.

discard(*values)

Discard value(s).

Parameters

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

Raises

ValueError – No values provided.

remove(*values)

Remove existing value(s).

Parameters

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

Raises
replace(old_value, new_value)

Replace existing value with a new one.

Parameters
  • old_value – Existing value.

  • new_value – New value.

update(iterable)

Update with iterable.

Parameters

iterable (collections.abc.Iterable) – Iterable.

Base Exception Class

class objetto.bases.BaseObjettoException

Base Objetto exception.

Inherits from:
Inherited By:

Base State Class

class objetto.bases.BaseState(initial=())

Base immutable state.

Inherits from:
Inherited By:
Parameters

initial – Initial values.

Raises

NotImplementedError – Abstract methods not implemented.

__hash__()

Get hash.

Returns

Hash.

Return type

int

abstract __eq__(other)

Compare for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

Raises

NotImplementedError – Abstract method not implemented.

__copy__()

Get copy.

Returns

Copy.

Return type

objetto.bases.BaseState

abstract __repr__()

Get representation.

Returns

Representation.

Return type

str

Raises

NotImplementedError – Abstract method not implemented.

__str__()

Get string representation.

Returns

String representation.

Return type

str

abstract property _internal

Internal values.

Base Structure Classes

class objetto.bases.BaseStructureMeta(name, bases, dct)

Metaclass for objetto.bases.BaseStructure.

Inherits from:
Inherited by:
Features:
property _unique_descriptor_name

Unique descriptor name or None.

Return type

str or None

property _unique_descriptor

Unique descriptor or None.

Return type

objetto.objects.UniqueDescriptor or objetto.data.UniqueDescriptor or None

abstract property _serializable_structure_types

Serializable structure types.

Return type

tuple[type[objetto.bases.BaseStructure]]

property _relationship_type

Relationship type.

Return type

type[objetto.bases.BaseRelationship]

class objetto.bases.BaseStructure

Base structure.

Metaclass:
Inherits from:
Inherited By:
Features:
  • Is hashable.

  • Is a protected collection.

  • Has state.

  • Unique hash based on ID if unique descriptor is defined.

  • Holds values at locations.

  • Has a relationship for each location.

  • Serializes/deserializes values and itself.

__hash__()

Get hash.

Returns

Hash.

Return type

int

__eq__(other)

Compare with another object for equality/identity.

Parameters

other – Another object.

Returns

True if equal or the exact same object.

Return type

bool

_hash()

Abstract

Get hash.

Returns

Hash.

Return type

int

Raises

RuntimeError – Abstract method not implemented by subclasses.

_eq(other)

Abstract

Compare with another object for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

Raises

RuntimeError – Abstract method not implemented by subclasses.

abstract classmethod _get_relationship(location)

Get relationship at location.

Parameters

location (collections.abc.Hashable) – Location.

Returns

Relationship.

Return type

objetto.bases.BaseRelationship

Raises

KeyError – Invalid location.

classmethod deserialize_value(serialized, location=None, **kwargs)

Deserialize value for location.

Parameters
  • serialized – Serialized value.

  • location (collections.abc.Hashable) – Location.

  • kwargs – Keyword arguments to be passed to the deserializers.

Returns

Deserialized value.

Raises
serialize_value(value, location=None, **kwargs)

Serialize value for location.

Parameters
  • value – Value.

  • location (collections.abc.Hashable) – Location.

  • kwargs – Keyword arguments to be passed to the serializers.

Returns

Serialized value.

Raises
abstract classmethod deserialize(serialized, **kwargs)

Deserialize.

Parameters
  • serialized – Serialized.

  • kwargs – Keyword arguments to be passed to the deserializers.

Returns

Deserialized.

Return type

objetto.bases.BaseStructure

Raises

objetto.exceptions.SerializationError – Can’t deserialize.

abstract serialize(**kwargs)

Serialize.

Parameters

kwargs – Keyword arguments to be passed to the serializers.

Returns

Serialized.

Raises

objetto.exceptions.SerializationError – Can’t serialize.

abstract property _state

State.

Return type

objetto.bases.BaseState

class objetto.bases.BaseInteractiveStructure

Base interactive structure.

Inherits from:
Inherited By:
Features:
  • Is an interactive collection/structure.

class objetto.bases.BaseMutableStructure

Base mutable structure.

Inherits from:
Inherited By:
Features:
  • Is a mutable collection/structure.

class objetto.bases.BaseAuxiliaryStructureMeta(name, bases, dct)

Metaclass for objetto.bases.BaseAuxiliaryStructure.

Inherits from:
Inherited by:
Features:
abstract property _base_auxiliary_type

Base auxiliary structure type.

Return type

type[objetto.bases.BaseAuxiliaryStructure]

class objetto.bases.BaseAuxiliaryStructure

Structure with a single relationship for all locations.

Inherits from:
Inherited By:
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.

classmethod _get_relationship(location=None)

Get relationship.

Parameters

location (collections.abc.Hashable) – Location.

Returns

Relationship.

Return type

objetto.bases.BaseRelationship

_relationship = BaseRelationship(checked=False, deserializer=None, factory=None, module=None, represented=True, serialized=True, serializer=None, subtypes=False, types=frozenset())

Class Attribute

Relationship for all locations.

Type

objetto.bases.BaseRelationship

class objetto.bases.BaseInteractiveAuxiliaryStructure

Base interactive auxiliary structure.

Inherits from:
Inherited By:
class objetto.bases.BaseMutableAuxiliaryStructure

Base mutable auxiliary structure.

Inherits from:
Inherited By:

Base Dict Structure Classes

class objetto.bases.BaseDictStructureMeta(name, bases, dct)

Metaclass for objetto.bases.BaseDictStructure.

Inherits from:
Inherited by:
Features:
property _key_relationship_type

Relationship type.

Return type

type[objetto.objects.KeyRelationship or objetto.data.KeyRelationship]

class objetto.bases.BaseDictStructure

Base dictionary structure.

Metaclass:
Inherits from:
Inherited By:
__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 – Invalid key.

__len__()

Get key count.

Returns

Key count.

Return type

int

__iter__()

Iterate over keys.

Returns

Key iterator.

Return type

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

__contains__(key)

Get whether key is present.

Parameters

key (collections.abc.Hashable) – Key.

Returns

True if contains.

Return type

bool

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

_key_relationship = KeyRelationship(checked=False, factory=None, module=None, subtypes=False, types=frozenset())

Class Attribute

Relationship for the keys.

Type

objetto.objects.KeyRelationship or objetto.data.KeyRelationship

abstract property _state

Internal state.

Return type

objetto.states.DictState

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseInteractiveDictStructure

Base interactive dictionary structure.

Inherits from:
Inherited By:
class objetto.bases.BaseMutableDictStructure

Base mutable dictionary structure.

Inherits from:
Inherited By:

Base List Structure Classes

class objetto.bases.BaseListStructureMeta(name, bases, dct)

Metaclass for objetto.bases.BaseListStructure.

Inherits from:
Inherited by:
class objetto.bases.BaseListStructure

Base list structure.

Metaclass:
Inherits from:
Inherited By:
__repr__()

Get representation.

Returns

Representation.

Return type

str

__reversed__()

Iterate over reversed values.

Returns

Reversed values iterator.

Return type

collections.abc.Iterator

__len__()

Get value count.

Returns

Value count.

Return type

int

__iter__()

Iterate over values.

Returns

Values iterator.

Return type

collections.abc.Iterator

__contains__(value)

Get whether value is present.

Parameters

value – Value.

Returns

True if contains.

Return type

bool

count(value)

Count number of occurrences of a 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.

abstract property _state

Internal state.

Return type

objetto.states.ListState

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseInteractiveListStructure

Base interactive list structure.

Inherits from:
Inherited By:
class objetto.bases.BaseMutableListStructure

Base mutable list structure.

Inherits from:
Inherited By:

Base Set Structure Classes

class objetto.bases.BaseSetStructureMeta(name, bases, dct)

Metaclass for objetto.bases.BaseSetStructure.

Inherits from:
Inherited by:
class objetto.bases.BaseSetStructure

Base set structure.

Metaclass:
Inherits from:
Inherited By:
__repr__()

Get representation.

Returns

Representation.

Return type

str

__len__()

Get value count.

Returns

Value count.

Return type

int

__iter__()

Iterate over values.

Returns

Values iterator.

Return type

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

__contains__(value)

Get whether value is present.

Parameters

value (collections.abc.Hashable) – Value.

Returns

True if contains.

Return type

bool

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

abstract property _state

Internal state.

Return type

objetto.states.SetState

Raises

NotImplementedError – Abstract method not implemented.

class objetto.bases.BaseInteractiveSetStructure

Base interactive set structure.

Inherits from:
Inherited By:
class objetto.bases.BaseMutableSetStructure

Base mutable set structure.

Inherits from:
Inherited By:

Base Attribute Structure Classes

class objetto.bases.BaseAttributeStructureMeta(name, bases, dct)

Metaclass for objetto.bases.BaseAttributeStructure.

Inherits from:
Inherited by:
Features:
abstract property _attribute_type

Attribute type.

Return type

type[objetto.bases.BaseAttribute]

property _attributes

Attributes mapped by name.

Return type

dict[str, objetto.bases.BaseAttribute]

property _attribute_names

Names mapped by attribute.

Return type

dict[objetto.bases.BaseAttribute, str]

class objetto.bases.BaseAttributeStructure

Base attribute structure.

Metaclass:
Inherits from:
Inherited by:
Features:
  • Holds values in attributes defined by descriptors.

  • Can be cast into a dictionary.

__repr__()

Get representation.

Returns

Representation.

Return type

str

__reversed__()

Iterate over reversed attribute names.

Returns

Reversed attribute names iterator.

Return type

collections.abc.Iterator[str]

__getitem__(name)

Get value for attribute name.

Parameters

name (str) – Attribute name.

Returns

Value.

Raises

KeyError – Attribute does not exist or has no value.

__len__()

Get count of attributes with value.

Returns

Count of attributes with value.

Return type

int

__iter__()

Iterate over names of attributes with value.

Returns

Names of attributes with value.

Return type

collections.abc.Iterator[str]

__contains__(name)

Get whether attribute name is valid and has a value.

Parameters

name (str) – Attribute name.

Returns

True if attribute name is valid and has a value.

Return type

bool

classmethod _get_relationship(location)

Get relationship at location (attribute name).

Parameters

location (str) – Location (attribute name).

Returns

Relationship.

Return type

objetto.bases.BaseRelationship

Raises

KeyError – Attribute does not exist.

classmethod _get_attribute(name)

Get attribute by name.

Parameters

name (str) – Attribute name.

Returns

Attribute.

Return type

objetto.bases.BaseAttribute

Raises

KeyError – Attribute does not exist.

abstract _set(name, value)

Set attribute value.

Parameters
  • name (str) – Attribute name.

  • value – Value.

Returns

Transformed.

Return type

objetto.bases.BaseAttributeStructure

Raises

AttributeError – Attribute is not changeable and already has a value.

abstract _delete(name)

Delete attribute value.

Parameters

name (str) – Attribute name.

Returns

Transformed.

Return type

objetto.bases.BaseAttributeStructure

Raises
abstract _update(*args, **kwargs)

Update multiple attribute values. Same parameters as dict.update().

Returns

Transformed.

Return type

objetto.bases.BaseAttributeStructure

Raises

AttributeError – Attribute is not changeable and already has a value.

keys()

Get names of the attributes with values.

Returns

Attribute names.

Return type

objetto.states.SetState[str]

find_with_attributes(**attributes)

Find first value that matches unique attribute values.

Parameters

attributes – Attributes to match.

Returns

Value.

Raises

ValueError – No attributes provided or no match found.

abstract property _state

Internal state.

Return type

objetto.states.DictState[str, Any]

class objetto.bases.BaseInteractiveAttributeStructure

Base interactive attribute structure.

Inherits from:
Inherited by:
set(name, value)

Set attribute value.

Parameters
  • name (str) – Attribute name.

  • value – Value.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveAttributeStructure

Raises

AttributeError – Attribute is not changeable and already has a value.

delete(name)

Delete attribute value.

Parameters

name (str) – Attribute name.

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveAttributeStructure

Raises
update(*args, **kwargs)

Update multiple attribute values. Same parameters as dict.update().

Returns

Transformed.

Return type

objetto.bases.BaseInteractiveAttributeStructure

Raises

AttributeError – Attribute is not changeable and already has a value.

class objetto.bases.BaseMutableAttributeStructure

Base mutable attribute structure.

Inherits from:
Inherited by:
__setitem__(name, value)

Set attribute value.

Parameters

name (str) – Attribute name.

Returns

Value.

Raises

KeyError – Attribute does not exist.

__delitem__(name)

Delete attribute value.

Parameters

name (str) – Attribute name.

Raises

KeyError – Attribute does not exist or has no value.

delete(name)

Delete attribute value.

Parameters

name (str) – Attribute name.

Raises

KeyError – Attribute does not exist or has no value.

set(name, value)

Set attribute value.

Parameters
  • name (str) – Attribute name.

  • value – Value.

Raises

KeyError – Attribute does not exist.

update(*args, **kwargs)

Update multiple attribute values. Same parameters as dict.update().

Raises

KeyError – Attribute does not exist.

Base Relationship Class

class objetto.bases.BaseRelationship(types=(), subtypes=False, checked=None, module=None, factory=None, serialized=True, serializer=None, deserializer=None, represented=True)

Relationship between a structure and its values.

Inherits from:
Inherited by:
Parameters
Raises
__hash__()

Get hash.

Returns

Hash.

Return type

int

__eq__(other)

Compare with another object for equality.

Parameters

other – Another object.

Returns

True if considered equal.

Return type

bool

__repr__()

Get representation.

Returns

Representation.

Return type

str

__str__()

Get string representation.

Returns

String representation.

Return type

str

to_dict()

Convert to dictionary.

Returns

Dictionary.

Return type

dict[str, Any]

get_single_exact_type(types=(<class 'type'>, ))

Get single exact type from available types if possible.

Parameters

types (str or type or None or tuple[str or type or None]) – Base types.

Returns

Single exact type that is a subclass of one of provided base types.

Return type

type or None

fabricate_value(value, factory=True, **kwargs)

Perform type check and run value through factory.

Parameters
  • value – Value.

  • factory (bool) – Whether to run value through factory.

  • kwargs – Keyword arguments to be passed to the factory.

Returns

Fabricated value.

property types

Types.

Return type

tuple[str or type]

property subtypes

Whether to accept subtypes.

Return type

bool

property checked

Whether to perform runtime type check.

Return type

bool

property module

Module path for lazy types/factories.

Return type

str or None

property factory

Value factory.

Return type

str or collections.abc.Callable or None

property serialized

Whether should be serialized.

Return type

bool

property serializer

Custom serializer.

Return type

str or collections.abc.Callable or None

property deserializer

Custom deserializer.

Return type

str or collections.abc.Callable or None

property represented

Whether should be represented.

Return type

bool

property passthrough

Whether does not perform type checks and has no factory.

Return type

bool

Base Attribute Class

class objetto.bases.BaseAttributeMeta(name, bases, dct)

Metaclass for objetto.bases.BaseAttribute.

Inherits from:
Inherited by:
Features:
  • Defines relationship type.

abstract property _relationship_type

Relationship type.

Return type

type[objetto.bases.BaseRelationship]

class objetto.bases.BaseAttribute(relationship=BaseRelationship(checked=False, deserializer=None, factory=None, module=None, represented=True, serialized=True, serializer=None, subtypes=False, types=frozenset()), default=<objetto._bases.bases.MISSING object>, default_factory=None, module=None, required=True, changeable=True, deletable=False, finalized=False, abstracted=False, metadata=None)

Base attribute descriptor for objetto.bases.BaseAttributeStructure classes.

Metaclass:
Inherits from:
Inherited by:
Parameters
  • relationship (objetto.bases.BaseRelationship) – Relationship.

  • default – Default value.

  • default_factory (str or collections.abc.Callable or None) – Default value factory.

  • module (str or None) – Optional module path to use in case partial paths are provided.

  • required (bool) – Whether attribute is required to have a value or not.

  • changeable (bool) – Whether attribute value can be changed.

  • deletable (bool) – Whether attribute value can be deleted.

  • finalized (bool) – If True, attribute can’t be overridden by subclasses.

  • abstracted (bool) – If True, attribute needs to be overridden by subclasses.

  • metadata – Metadata.

Raises
  • TypeError – Invalid parameter type.

  • ValueError – Invalid parameter value.

  • ValueError – Can’t specify both ‘default’ and ‘default_factory’ arguments.

  • ValueError – Can’t be ‘required’ and ‘deletable’ at the same time.

  • ValueError – Can’t be ‘finalized’ and ‘abstracted’ at the same time.

__get__(instance, owner)

Get attribute value when accessing from valid instance or when attribute is constant. Get this descriptor otherwise.

Parameters
Returns

Value or this descriptor.

Return type

Any or objetto.bases.BaseAttribute

__hash__()

Get hash based on object id.

Returns

Hash based on object id.

Return type

int

__eq__(other)

Compare with another object for identity.

Parameters

other – Another object.

Returns

True if the same object.

Return type

bool

__repr__()

Get representation.

Returns

Representation.

Return type

str

to_dict()

Convert to dictionary.

Returns

Dictionary.

Return type

dict[str, Any]

copy(**kwargs)

Make a copy of this attribute and optionally change some of its parameters.

Parameters

kwargs – New parameters.

Returns

New attribute.

Return type

objetto.bases.BaseAttribute

get_name(instance)

Get attribute name.

Parameters

instance (objetto.bases.BaseAttributeStructure) – Instance.

Returns

Attribute Name.

Return type

str

get_value(instance)

Get attribute value.

Parameters

instance (objetto.bases.BaseAttributeStructure) – Instance.

Returns

Attribute Value.

Raises

AttributeError – Could not get value.

fabricate_default_value(**kwargs)

Fabricate default value.

Parameters

kwargs – Keyword arguments to be passed to the factories.

Returns

Fabricated value.

Raises

ValueError – No default or default factory.

property relationship

Relationship.

Return type

objetto.bases.BaseRelationship

property default

Default value.

property default_factory

Default value factory.

Return type

str or collections.abc.Callable or None

property module

Optional module path to use in case partial paths are provided.

Return type

str or None

property required

Whether attribute is required to have a value or not.

Return type

bool

property changeable

Whether attribute value can be changed.

Return type

bool

property deletable

Whether attribute value can be deleted.

Return type

bool

property finalized

If True, attribute can’t be overridden by subclasses.

Return type

bool

property abstracted

If True, attribute needs to be overridden by subclasses.

Return type

bool

property has_default

Whether attribute has a default value or a default factory.

Return type

bool

property constant

Whether attribute is constant.

Return type

bool

Base Data Classes

class objetto.bases.BaseDataMeta(name, bases, dct)

Metaclass for objetto.bases.BaseData.

Inherits from:
Inherited by:
Features:
property _serializable_structure_types

Serializable structure types.

Return type

tuple[type[objetto.bases.BaseData]]

property _relationship_type

Relationship type.

Return type

type[objetto.data.DataRelationship]

class objetto.bases.BaseData

Base data.

Metaclass:
Inherits from:
Inherited by:
Features:
  • Is an immutable protected structure.

__copy__()

Get copy.

Returns

Copy.

Return type

objetto.bases.BaseData

__invariant__()

Gets called whenever a new instance is made. Can be used for validation.

property _state

State.

Return type

objetto.bases.BaseState

class objetto.bases.BaseInteractiveData

Base interactive data.

Inherits from:
Inherited by:
Features:
  • Is an immutable interactive data structure.

class objetto.bases.BaseAuxiliaryDataMeta(name, bases, dct)

Metaclass for objetto.bases.BaseAuxiliaryData.

Inherits from:
Inherited by:
Features:
  • Defines a base auxiliary type.

abstract property _base_auxiliary_type

Base auxiliary data type.

Return type

type[objetto.bases.BaseAuxiliaryData]

class objetto.bases.BaseAuxiliaryData

Base auxiliary data.

Metaclass:
Inherits from:
Inherited by:
_hash()

Get hash.

Returns

Hash.

Return type

int

_eq(other)

Compare with another object for equality.

Parameters

other – Another object.

Returns

True if equal.

Return type

bool

find_with_attributes(**attributes)

Find first value that matches unique attribute values.

Parameters

attributes – Attributes to match.

Returns

Value.

Raises

ValueError – No attributes provided or no match found.

_relationship = DataRelationship(checked=False, compared=True, deserializer=None, factory=None, module=None, represented=True, serialized=True, serializer=None, subtypes=False, types=frozenset())

Relationship for all locations.

Type

objetto.data.DataRelationship

class objetto.bases.BaseInteractiveAuxiliaryData

Base interactive auxiliary data.

Inherits from:
Inherited by:

Base Object Classes

class objetto.bases.BaseObjectMeta(name, bases, dct)

Metaclass for objetto.bases.BaseObject.

Inherits from:
Inherited by:
Features:
Raises

TypeError – Class has multiple history descriptors.

abstract property _state_factory

State factory.

Return type

type[objetto.bases.BaseState]

property _serializable_structure_types

Serializable structure types.

Return type

tuple[type[objetto.bases.BaseObject], type[objetto.bases.BaseData]]

property _relationship_type

Relationship type.

Return type

type[objetto.objects.Relationship]

property _history_descriptor_name

History descriptor name or None.

Return type

str or None

property _history_descriptor

History descriptor or None.

Return type

objetto.objects.HistoryDescriptor or None

property _reactions

Reactions sorted by priority.

Return type

tuple[objetto.bases.BaseReaction]

property _data_methods

Data method functions.

Return type

dict[str, function]

abstract property Data

Data type.

Return type

type[objetto.bases.BaseData]

class objetto.bases.BaseObject(app)

Base object.

Metaclass:
Inherits from:
Inherited By:
Features:
  • Is a protected structure.

Parameters

app (objetto.applications.Application) – Application.

__copy__()

Get copy by using serialization.

Returns

Copy.

Return type

objetto.bases.BaseObject

__post_deserialize__()

This magic method gets automatically called after deserialization.

_hash()

Get hash based on object id.

Returns

Hash based on object id.

Return type

int

_eq(other)

Compare with another object for identity.

Parameters

other – Another object.

Returns

True if the same object.

Return type

bool

abstract _locate(child)

Locate child object.

Parameters

child (objetto.bases.BaseObject) – Child object.

Returns

Location.

Return type

collections.abc.Hashable

Raises

ValueError – Could not locate child.

abstract _locate_data(child)

Locate child object’s data.

Parameters

child (objetto.bases.BaseObject) – Child object.

Returns

Data location.

Return type

collections.abc.Hashable

Raises

ValueError – Could not locate child’s data.

_in_same_application(value)

Get whether a value is an object and belongs to the same application as this.

Parameters

value – Any value or object.

Returns

True if is an object and belongs to the same application.

Return type

bool

_batch_context()

Batch context.

Parameters
  • name (str) – Batch name.

  • metadata – Metadata.

Returns

Batch context manager.

Return type

contextlib.AbstractContextManager[collections.abc.Iterator[objetto.changes.Batch]]

abstract classmethod deserialize(serialized, app=None, **kwargs)

Deserialize.

Parameters
Returns

Deserialized.

Return type

objetto.bases.BaseObject

Raises
property _state

State.

Return type

objetto.states.BaseState

property _parent

Parent object or None.

Return type

objetto.bases.BaseObject or None

property _is_root

Whether object is root.

Return type

bool

property _children

Children objects.

Return type

objetto.states.SetState[objetto.bases.BaseObject]

property _history

History.

Return type

objetto.history.HistoryObject or None

property app

Application.

Return type

objetto.applications.Application

property data

Data.

Return type

objetto.bases.BaseData or None

class objetto.bases.BaseMutableObject(app)

Base mutable object.

Inherits from:
Inherited By:
Features:
  • Is an mutable object structure.

class objetto.bases.BaseAuxiliaryObjectMeta(name, bases, dct)

Metaclass for objetto.bases.BaseAuxiliaryObject.

Inherits from:
Inherited by:
Features:
  • Defines a base auxiliary type.

  • Defines a base auxiliary Data type.

  • Constructs automatic Data class.

abstract property _base_auxiliary_type

Base auxiliary object type.

Return type

type[objetto.bases.BaseAuxiliaryObject]

abstract property _base_auxiliary_data_type

Base auxiliary data type.

Return type

type[objetto.bases.BaseAuxiliaryData]

property Data

Data type.

Return type

type[objetto.bases.BaseAuxiliaryData]

class objetto.bases.BaseAuxiliaryObject(app)

Base auxiliary object.

Metaclass:
Inherits from:
Inherited By:
find_with_attributes(**attributes)

Find first value that matches unique attribute values. This method will be optimized if the auxiliary objects is utiling the objetto.reactions.UniqueAttributes reaction, which caches unique attributes as indexes.

Parameters

attributes – Attributes to match.

Returns

Value.

Raises

ValueError – No attributes provided or no match found.

_relationship = Relationship(checked=False, child=True, data=True, data_relationship=DataRelationship(checked=False, compared=True, deserializer=None, factory=None, module=None, represented=True, serialized=True, serializer=None, subtypes=False, types=frozenset()), deserializer=None, factory=None, history=True, module=None, represented=True, serialized=True, serializer=None, subtypes=False, types=frozenset())

Relationship for all locations.

Type

objetto.objects.Relationship

class objetto.bases.BaseMutableAuxiliaryObject(app)

Base mutable auxiliary object.

Inherits from:
Inherited By:

Base Proxy Object Class

class objetto.bases.BaseProxyObject(obj)

Base auxiliary proxy object.

Inherits from:
Inherited By:
Parameters

obj (objetto.bases.BaseAuxiliaryObject) – Auxiliary object.

__repr__()

Get representation.

Returns

Representation.

Return type

str

__hash__()

Get hash based on object id.

Returns

Hash based on object id.

Return type

int

__eq__(other)

Compare with another object for identity.

Parameters

other – Another object.

Returns

True if the same object.

Return type

bool

__len__()

Get count.

Returns

Count.

Return type

int

__iter__()

Iterate over.

Returns

Iterator.

Return type

collections.abc.Iterator

__contains__(value)

Get whether value is present.

Parameters

value – Value.

Returns

True if contains.

Return type

bool

_clear()

Clear.

Returns

Transformed.

Return type

objetto.bases.BaseProxyObject

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.

property _obj

Auxiliary object.

Return type

objetto.bases.BaseAuxiliaryObject

property _state

State.

Return type

objetto.bases.BaseState

property _parent

Parent object or None.

Return type

objetto.bases.BaseObject or None

property _is_root

Whether object is root.

Return type

bool

property _children

Children objects.

Return type

objetto.states.SetState[objetto.bases.BaseObject]

property _history

History or None.

Return type

objetto.history.HistoryObject or None

property app

Application.

Return type

objetto.applications.Application

property data

Data.

Return type

objetto.bases.BaseData or None

Base Reaction Class

class objetto.bases.BaseReaction

Base method-like that gets called whenever an action is sent through the object.

Inherits from:
Inherited by:
abstract __call__(obj, action, phase)

React to actions.

Parameters
__get__(instance, owner)

Get bound reaction method from valid instance or this descriptor otherwise.

Parameters
Returns

Bound reaction method or this descriptor.

Return type

function or objetto.bases.BaseReaction

__hash__()

Get hash.

Returns

Hash.

Return type

int

__eq__(other)

Compare with another object for equality.

Parameters

other – Another object.

Returns

True if considered equal.

Return type

bool

__repr__()

Get representation.

Returns

Representation.

Return type

str

to_dict()

Convert to dictionary.

Returns

Dictionary.

Return type

dict[str, Any]

set_priority(priority)

Set priority and return a new reaction.

Parameters

priority (int or None) – Priority.

Returns

New reaction.

Return type

objetto.bases.BaseReaction

property priority

Priority.

Return type

int or None

Base Factory Class

class objetto.bases.BaseFactory

Base callable factory object.

Inherits from:
Inherited By:
abstract __call__(value, **kwargs)

Call with input value and optional keyword arguments.

Parameters
  • value – Input value.

  • kwargs – Keyword arguments.

Returns

Output value.

__add__(other)

Add with another factory.

Parameters

other (objetto.bases.BaseFactoryor str or collections.abc.Callable or None) – Another factory.

Returns

Multi factory with added factories.

Return type

objetto.factories.MultiFactory

Base Serializer Class

class objetto.bases.BaseSerializer

Base callable serializer object.

Inherits from:
Inherited By:
abstract __call__(value, **kwargs)

Call with value and optional keyword arguments.

Parameters
  • value – Value.

  • kwargs – Keyword arguments.

Returns

Serialized.

Base Deserializer Class

class objetto.bases.BaseDeserializer

Base callable deserializer object.

Inherits from:
Inherited By:
abstract __call__(serialized, **kwargs)

Call with value and optional keyword arguments.

Parameters
  • serialized – Serialized.

  • kwargs – Keyword arguments.

Returns

Value.

Base Change Classes

class objetto.bases.BaseChange(**initial)

Base change.

Inherits from:
Inherited By:
name :  Data Attribute

Name describing the change.

Type

str

obj :  Data Attribute

Object being changed.

Type

objetto.bases.BaseObject

is_atomic :  Data Attribute

Whether change is atomic or not.

Type

bool

class objetto.bases.BaseAtomicChange(**initial)

Base atomic change.

Inherits from:
Inherited By:
old_state :  Data Attribute

Object state before the change.

Type

objetto.bases.BaseState

new_state :  Data Attribute

Object state after the change.

Type

objetto.bases.BaseState

old_children :  Data Attribute

Children objects being released.

Type

objetto.data.SetData[objetto.bases.BaseObject]

new_children :  Data Attribute

Children objects being adopted.

Type

objetto.data.SetData[objetto.bases.BaseObject]

history_adopters :  Data Attribute

Objects adopting the history from the object being changed.

Type

objetto.data.SetData[objetto.bases.BaseObject]

history :  Data Attribute

History where this changed originated from (result of an redo/undo operation).

Type

objetto.history.HistoryObject or None

is_atomic :  Data Attribute

Whether change is atomic or not.

Type

bool

Base Phase Enum

class objetto.bases.Phase(value)

Action phase.

PRE = 'PRE'

Before the changes.

POST = 'POST'

After the changes.

Abstract Member Classes

final class objetto.bases.AbstractMemberMeta(name, bases, dct)

Metaclass for objetto.bases.AbstractMember.

Inherits from:
Features:
  • Enforces abstract tag.

__repr__()

Get class representation.

Returns

Class representation.

Return type

str

final class objetto.bases.AbstractMember(*args, **kwargs)

Abstract member for classes.

Note

Do not use this class directly. Use the helper function objetto.bases.abstract_member() instead.

Metaclass:
Inherits from:
Features:
  • Prevents class from instantiating if not overriden by a concrete member.