Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/conditions_without_deep_copied_ctx_and_actor: add new condition … #76

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dff/script/core/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __init__(
if script.get(fallback_label[0], {}).get(fallback_label[1]) is None:
raise ValueError(f"Unkown fallback_label={fallback_label}")
if condition_handler is None:
condition_handler = deep_copy_condition_handler
condition_handler = default_condition_handler

super(Actor, self).__init__(
script=script,
Expand Down Expand Up @@ -372,12 +372,12 @@ def validate_script(self, verbose: bool = True):
labels += list(node.transitions.keys())
conditions += list(node.transitions.values())

actor = self.copy(deep=True)
error_msgs = []
for flow_label, node_label, label, condition in zip(flow_labels, node_labels, labels, conditions):
ctx = Context()
ctx.validation = True
ctx.add_request(Message(text="text"))
actor = self.copy(deep=True)

label = label(ctx, actor) if isinstance(label, Callable) else normalize_label(label, flow_label)

Expand Down Expand Up @@ -426,14 +426,14 @@ def validate_script(self, verbose: bool = True):


@validate_arguments()
def deep_copy_condition_handler(
def default_condition_handler(
condition: Callable, ctx: Context, actor: Actor, *args, **kwargs
) -> Callable[[Context, Actor, Any, Any], bool]:
"""
This function returns a deep copy of the callable conditions:
The simplest and quickest condition handler for trivial condition handling returns the callable condition:

:param condition: Condition to copy.
:param ctx: Context of current condition.
:param actor: Actor we use in this condition.
"""
return condition(ctx.copy(deep=True), actor.copy(deep=True), *args, **kwargs)
return condition(ctx, actor, *args, **kwargs)