Skip to content

Commit 57e0225

Browse files
authored
fix: ensure that PazyApply.result returns a non-lazy value (#1101)
Signed-off-by: Louis Mandel <[email protected]>
1 parent c23aca4 commit 57e0225

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/pdl/pdl_lazy.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,24 @@ def __init__(
156156

157157
@property
158158
def data(self):
159-
return self.result()
160-
161-
def __repr__(self):
162-
return self.result().__repr__()
163-
164-
def result(self) -> ApplyOutputT:
165159
if self._done:
166160
return self._data
167161
v = self.x.result()
168162
self._data = self.f(v)
169163
self._done = True
170164
return self._data
171165

166+
def __repr__(self):
167+
return self.result().__repr__()
168+
169+
def result(self) -> ApplyOutputT:
170+
data = self.data
171+
if isinstance(data, PdlLazy):
172+
result = data.result()
173+
else:
174+
result = data
175+
return result # pyright: ignore
176+
172177

173178
LazyApplyInputT = TypeVar("LazyApplyInputT")
174179
LazyApplyOutputT = TypeVar("LazyApplyOutputT")
@@ -192,20 +197,14 @@ def __init__(
192197
x1: PdlLazy[Apply2Input1T],
193198
x2: PdlLazy[Apply2Input2T],
194199
):
195-
self._data: Apply2OutputT
200+
self._data: Apply2OutputT | PdlLazy[Apply2OutputT]
196201
self.f = f
197202
self.x1 = x1
198203
self.x2 = x2
199204
self._done = False
200205

201206
@property
202-
def data(self):
203-
return self.result()
204-
205-
def __repr__(self):
206-
return self.result().__repr__()
207-
208-
def result(self) -> Apply2OutputT:
207+
def data(self) -> Apply2OutputT | PdlLazy[Apply2OutputT]:
209208
if self._done:
210209
return self._data
211210
if isinstance(self.x1, PdlLazy):
@@ -220,6 +219,17 @@ def result(self) -> Apply2OutputT:
220219
self._done = True
221220
return self._data
222221

222+
def __repr__(self):
223+
return self.result().__repr__()
224+
225+
def result(self) -> Apply2OutputT:
226+
data = self.data
227+
if isinstance(data, PdlLazy):
228+
result = data.result()
229+
else:
230+
result = data
231+
return result # pyright: ignore
232+
223233

224234
LazyApply2Input1T = TypeVar("LazyApply2Input1T") # pylint: disable=invalid-name
225235
LazyApply2Input2T = TypeVar("LazyApply2Input2T") # pylint: disable=invalid-name

0 commit comments

Comments
 (0)