Action starter packs
conatus.actions.starter_packs.ActionStarterPack
¶
ActionStarterPack(
*raw_actions: Action
| ActionBlueprint
| FunctionType
| Self,
)
A starter pack, or collection, of actions.
Starter packs are meant to be used as a substitute to a list of
Action or ActionBlueprint
objects in constructors.
In other words:
from conatus import action, Task
from conatus.actions.starter_packs import ActionStarterPack
@action
def action_0(): ...
@action
def action_1(): ...
# Ok, but a bit verbose
task = Task(
description="This is a task",
name="task",
actions=[action_0, action_1],
)
starter_pack = ActionStarterPack(action_0, action_1)
# Cleaner
task = Task(
description="This is a task",
name="task",
actions=starter_pack,
)
This is especially useful to pass browsing actions, which tend to be plentiful and not easily remembered.
Other classes like BaseTask will expect
that the actions are in the form of a list of Action
instances, and that they can be retrieved
with the actions
property.
You can also use:
- the
+and-operators to add and remove actions from the starter pack. - the
lenfunction to get the number of actions in the starter pack.
You just pass the actions you want to include in the starter pack, one after the other:
from conatus.actions.starter_packs import ActionStarterPack
from conatus.actions.preloaded.browsing import (
browser_close,
browser_goto,
browser_start,
)
browsing_actions = ActionStarterPack(
browser_start,
browser_goto,
browser_close,
)
| PARAMETER | DESCRIPTION |
|---|---|
raw_actions
|
The actions to include in the starter pack, in
'raw form', meaning that they can be any of the following:
-
TYPE:
|
Source code in conatus/actions/starter_packs.py
from_existing
classmethod
¶
from_existing(
actions: list[Action],
actions_with_original: list[
tuple[
Action,
Action | ActionBlueprint | FunctionType | Self,
]
],
) -> Self
Create a new starter pack from an existing one.
| PARAMETER | DESCRIPTION |
|---|---|
actions
|
The actions to include in the starter pack. |
actions_with_original
|
The actions with original to include in the starter pack.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The new starter pack. |
Source code in conatus/actions/starter_packs.py
__add__
¶
__add__(
other: Action | ActionBlueprint | FunctionType | Self,
) -> Self
Add an action to the starter pack.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The action to add to the starter pack.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The starter pack with the action added. |
Source code in conatus/actions/starter_packs.py
__radd__
¶
__radd__(
other: Action | ActionBlueprint | FunctionType | Self,
) -> Self
Add an action to the starter pack.
This is the same as __add__
.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The action to add to the starter pack.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The starter pack with the action added. |
Source code in conatus/actions/starter_packs.py
__iadd__
¶
__iadd__(
other: Action | ActionBlueprint | FunctionType | Self,
) -> Self
Add an action to the starter pack.
This is the same as __add__
.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The action to add to the starter pack.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The starter pack with the action added. |
Source code in conatus/actions/starter_packs.py
__sub__
¶
__sub__(
other: Action | ActionBlueprint | FunctionType | Self,
) -> Self
Remove an action from the starter pack.
Note that if you pass a class instance, or a function, we will do our best effort to remove it from the starter pack, but this might not always be possible.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The action to remove from the starter pack.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The starter pack with the action removed. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the action is not found in the starter pack. |
Source code in conatus/actions/starter_packs.py
__rsub__
¶
__rsub__(
other: Action | ActionBlueprint | FunctionType | Self,
) -> Self
Remove an action from the starter pack.
This is the same as __sub__
.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The action to remove from the starter pack.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The starter pack with the action removed. |
Source code in conatus/actions/starter_packs.py
__isub__
¶
__isub__(
other: Action | ActionBlueprint | FunctionType | Self,
) -> Self
Remove an action from the starter pack.
This is the same as __sub__
.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The action to remove from the starter pack.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The starter pack with the action removed. |
Source code in conatus/actions/starter_packs.py
__len__
¶
__len__() -> int