Private API¶
For those interested in (non-public) API.
Utility classes¶
- roles.role.class_fields(cls: Type, exclude: Sequence[str] = ('__doc__', '__module__', '__dict__', '__weakref__', '__slots__')) Set[str] ¶
Get all fields declared in a class, including superclasses.
Don’t forget to clear the cache if fields are added to a class or role!
Context internals¶
- class roles.context.CurrentContextManager¶
The default application wide context stack.
Put a new context class on the context stack. This functionality should be called with the context class as first argument.
>>> class SomeContext: ... pass # define some methods, define some roles ... def execute(self): ... with context(self): ... pass # do something
Roles can be fetched from the context by calling
context.name
. Just like that.You can provide additional bindings to be performed:
>>> from roles.role import RoleType
>>> class SomeRole(metaclass=RoleType): ... pass
>>> class SomeContext: ... def __init__(self, data_object): ... self.data_object = data_object ... def execute(self): ... with context(self, data_object=SomeRole): ... pass # do something
Those bindings are applied when the context is entered (in this case immediately).