From ccc4009dd5e854ea698682620f2ef26802c11c78 Mon Sep 17 00:00:00 2001 From: Eddie Bergman Date: Thu, 23 May 2024 22:39:39 +0200 Subject: [PATCH] fix(pipeline): `request` now fails without default (#284) --- src/amltk/pipeline/node.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/amltk/pipeline/node.py b/src/amltk/pipeline/node.py index 79d9b35c..02e3c35b 100644 --- a/src/amltk/pipeline/node.py +++ b/src/amltk/pipeline/node.py @@ -183,7 +183,13 @@ def __call__( P = ParamSpec("P") -_NotSet = object() +class _NotSetType: + @override + def __repr__(self) -> str: + return "" + + +_NotSet = _NotSetType() class RichOptions(NamedTuple): @@ -197,6 +203,8 @@ class RichOptions(NamedTuple): class ParamRequest(Generic[T]): """A parameter request for a node. This is most useful for things like seeds.""" + _has_default: bool + key: str """The key to request under.""" @@ -211,7 +219,10 @@ class ParamRequest(Generic[T]): @property def has_default(self) -> bool: """Whether this request has a default value.""" - return self.default is not _NotSet + # NOTE(eddiebergman): We decide to calculate this on + # initialization as when sent to new processes, these object + # ids may not match + return self._has_default def request(key: str, default: T | object = _NotSet) -> ParamRequest[T]: @@ -224,7 +235,7 @@ def request(key: str, default: T | object = _NotSet) -> ParamRequest[T]: config once [`configure`][amltk.pipeline.Node.configure] is called and nothing has been provided. """ - return ParamRequest(key=key, default=default) + return ParamRequest(key=key, default=default, _has_default=default is not _NotSet) @dataclass(init=False, frozen=True, eq=True)