Skip to content

Commit 0112df9

Browse files
committed
add test for named return values for with continuations
1 parent e818fd8 commit 0112df9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

unpythonic/seq.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def lazy_begin0(*bodys):
9999
body()
100100
return out
101101

102-
# TODO: expand tests of `continuations` to cases with named return values
103102
# TODO: update code examples in docs
104103

105104
# sequence one-input, one-output functions

unpythonic/syntax/tests/test_conts.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ def doit():
236236
test[k('again') == ['the call returned', 'again']]
237237
test[k('thrice', '!') == ['the call returned', 'thrice', '!']]
238238

239+
with testset("integration with named return values"):
240+
# Named return values aren't supported as assignment targets in a `call_cc[]`
241+
# due to syntactic limitations. But they can be used elsewhere in continuation-enabled code.
242+
with continuations:
243+
def f1(x, y):
244+
return Values(x=x, y=y) # named return values
245+
def f2(*, x, y): # note keyword-only parameters
246+
return x, y # one return value, a tuple (for multiple-return-values, use `Values(...)`)
247+
# Think through carefully what this does: call `f1`, chain to `f2` as the continuation.
248+
# The continuation is set here by explicitly providing a value for the implicit `cc` parameter.
249+
#
250+
# The named return values from `f1` are then unpacked, by the continuation machinery,
251+
# into the kwargs of `f2`. Then `f2` takes those, and returns a tuple.
252+
test[f1(2, 3, cc=f2) == (2, 3)]
253+
239254
with testset("top level call_cc"):
240255
# A top-level "call_cc" is also allowed.
241256
#

0 commit comments

Comments
 (0)