-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ability for action to specify its own source code
This enables people to build classes that have different sources (E.G. function wrappers)
- Loading branch information
1 parent
a295c07
commit e10db73
Showing
3 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from burr.core import Action, State | ||
from burr.tracking.common.models import ActionModel | ||
|
||
|
||
class ActionWithCustomSource(Action): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
@property | ||
def reads(self) -> list[str]: | ||
return [] | ||
|
||
def run(self, state: State, **run_kwargs) -> dict: | ||
return {} | ||
|
||
@property | ||
def writes(self) -> list[str]: | ||
return [] | ||
|
||
def update(self, result: dict, state: State) -> State: | ||
return state | ||
|
||
def get_source(self) -> str: | ||
return "custom source code" | ||
|
||
|
||
def test_action_with_custom_source(): | ||
model = ActionModel.from_action(ActionWithCustomSource().with_name("foo")) | ||
assert model.code == "custom source code" |