From e577a4a5821fe4fc7626c7bb48fcd41776dbf82c Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 16 May 2024 21:50:09 -0400 Subject: [PATCH] Fix lazy --- src/controlflow/decorators.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/controlflow/decorators.py b/src/controlflow/decorators.py index 1c89239d..b8aa62fa 100644 --- a/src/controlflow/decorators.py +++ b/src/controlflow/decorators.py @@ -96,13 +96,14 @@ def wrapped_flow(*args, lazy_=None, **kwargs): with controlflow.instructions(instructions): result = fn(*args, **kwargs) - # determine if we should run the flow eagerly or lazily + # Determine if we should run eagerly or lazily if lazy_ is not None: - lazy = lazy_ - if lazy is None: - run_eagerly = controlflow.settings.eager_mode - else: + run_eagerly = not lazy_ + elif lazy is not None: run_eagerly = not lazy + else: + run_eagerly = controlflow.settings.eager_mode + if run_eagerly: flow_obj.run() @@ -194,13 +195,14 @@ def wrapper(*args, lazy_: bool = None, **kwargs): tools=tools or [], ) - # determine if we should run the flow eagerly or lazily + # Determine if we should run eagerly or lazily if lazy_ is not None: - lazy = lazy_ - if lazy is None: - run_eagerly = controlflow.settings.eager_mode - else: + run_eagerly = not lazy_ + elif lazy is not None: run_eagerly = not lazy + else: + run_eagerly = controlflow.settings.eager_mode + if run_eagerly: task.run() return task.result