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

sentinel object #116

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion znflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
from znflow.graph import DiGraph


class _NOT_RESVOLED_TYPE:
pass


NOT_RESVOLED = _NOT_RESVOLED_TYPE()


@contextlib.contextmanager
def disable_graph(*args, **kwargs):
"""Temporarily disable set the graph to empty.
Expand Down Expand Up @@ -354,7 +361,7 @@ class FunctionFuture(NodeBaseMixin):
kwargs: typing.Dict
item: any = None

result: any = dataclasses.field(default=None, init=False, repr=True)
result: any = dataclasses.field(default=NOT_RESVOLED, init=False, repr=True)

_protected_ = NodeBaseMixin._protected_ + ["function", "args", "kwargs"]

Expand Down
4 changes: 2 additions & 2 deletions znflow/dynamic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing as t

from znflow.base import Connection, disable_graph, get_graph, FunctionFuture
from znflow.base import Connection, disable_graph, get_graph, FunctionFuture, NOT_RESVOLED


def resolve(value: t.Union[Connection, t.Any]) -> t.Any:
Expand All @@ -25,7 +25,7 @@ def resolve(value: t.Union[Connection, t.Any]) -> t.Any:
# get the actual value
with disable_graph():
result = value.result
if result is not None:
if result is not NOT_RESVOLED:
return result
# we assume, that if the result is None, the node has not been run yet
graph = get_graph()
Expand Down
Loading