API documentation

tri_declarative.declarative(member_class=None, parameter='members', add_init_kwargs=True, sort_key=None, is_member=None)[source]

Class decorator to enable classes to be defined in the style of django models. That is, @declarative classes will get an additional argument to constructor, containing a dict with all class members matching the specified type.

Parameters:
  • member_class (class) – Class(es) to collect
  • is_member ((object) -> bool) – Function to determine if an object should be collected
  • parameter (str) – Name of constructor parameter to inject
  • add_init_kwargs (bool) – If constructor parameter should be injected (Default: True)
  • sort_key ((object) -> object) – Function to invoke on members to obtain ordering (Default is to use ordering from creation_ordered)
tri_declarative.evaluate_recursive_strict(func_or_value, __signature=None, **kwargs)[source]

Like evaluate_recursive but won’t allow un-evaluated callables to slip through.

tri_declarative.getattr_path(obj, path, default=<object object>)[source]

Get an attribute path, as defined by a string separated by ‘__’. getattr_path(foo, ‘a__b__c’) is roughly equivalent to foo.a.b.c but will short circuit to return None if something on the path is None. If no default value is provided AttributeError is raised if an attribute is missing somewhere along the path. If a default value is provided that value is returned.

tri_declarative.get_members(cls, member_class=None, is_member=None, sort_key=None, _parameter=None)[source]

Collect all class level attributes matching the given criteria.

Parameters:
  • cls – Class to traverse
  • member_class (class) – Class(es) to collect
  • is_member ((object) -> bool) – Function to determine if an object should be collected
  • sort_key ((object) -> object) – Function to invoke on members to obtain ordering (Default is to use ordering from creation_ordered)
class tri_declarative.Namespace(*dicts, **kwargs)[source]
__call__(*args, **kwargs)[source]

Call self as a function.

__init__(*dicts, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

tri_declarative.setattr_path(obj, path, value)[source]

Set an attribute path, as defined by a string separated by ‘__’. setattr_path(foo, ‘a__b__c’, value) is equivalent to “foo.a.b.c = value”.

class tri_declarative.Shortcut(*dicts, **kwargs)[source]
tri_declarative.with_meta(class_to_decorate=None, add_init_kwargs=True)[source]

Class decorator to enable a class (and it’s sub-classes) to have a ‘Meta’ class attribute.

Parameters:add_init_kwargs (bool) – Pass Meta class members to constructor
Return type:class