Skip to content

Commit 11dc899

Browse files
committed
naming: setescape should use 'tags' since it accepts a tuple
1 parent 4329c16 commit 11dc899

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,10 @@ To make this work with lambdas, and for uniformity of syntax, **in trampolined f
560560
For more control, both ``@setescape`` points and ``escape`` instances can be tagged:
561561

562562
```python
563-
@setescape(tag="foo") # setescape point tag can be single value or tuple (tuples OR'd, like isinstance())
563+
@setescape(tags="foo") # setescape point tags can be single value or tuple (tuples OR'd, like isinstance())
564564
def foo():
565565
@immediate
566-
@setescape(tag="bar")
566+
@setescape(tags="bar")
567567
def bar():
568568
@looped
569569
def s(loop, acc=0, i=0):

tour.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ def s(loop, acc=0, i=0):
368368
assert f() == 15
369369

370370
# tagged escapes to control where the escape is sent:
371-
# setescape point tag can be single value or tuple (tuples OR'd, like isinstance())
372-
@setescape(tag="foo")
371+
# setescape point tags can be single value or tuple (tuples OR'd, like isinstance())
372+
@setescape(tags="foo")
373373
def foo():
374374
@immediate
375-
@setescape(tag="bar")
375+
@setescape(tags="bar")
376376
def bar():
377377
@looped
378378
def s(loop, acc=0, i=0):

unpythonic/ec.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, value, tag=None):
2424
self.value = value
2525
self.tag = tag
2626

27-
def setescape(tag=None):
27+
def setescape(tags=None):
2828
"""Decorator. Mark function as exitable by ``raise escape(value)``.
2929
3030
In Lisp terms, this essentially captures the escape continuation (ec)
@@ -34,10 +34,12 @@ def setescape(tag=None):
3434
to ``return escape(value)``. The trampoline specifically detects ``escape``
3535
instances, and performs the ``raise``.
3636
37-
Technically, this is a decorator factory; the optional tag parameter can be
38-
used to catch only those escapes with the same tag. ``tag`` can be a single
39-
value, or a tuple. Single value means catch that specific tag; tuple means
40-
catch any of those tags. Default is None, i.e. catch all.
37+
Technically, this is a decorator factory; the optional ``tags`` parameter
38+
can be used to catch only those escapes having one of the given tags.
39+
40+
``tags`` can be a single value, or a tuple. Single value means catch only
41+
that one tag; tuple means catch any of those tags. Default is None,
42+
i.e. catch all instances of ``escape``.
4143
4244
Multi-return using escape continuation::
4345
@@ -83,12 +85,11 @@ def s(loop, acc=0, i=0):
8385
return False
8486
assert f() == 15
8587
"""
86-
if tag is None:
87-
tags = None
88-
elif isinstance(tag, (tuple, list)): # multiple tags
89-
tags = set(tag)
90-
else: # single tag
91-
tags = set((tag,))
88+
if tags is not None:
89+
if isinstance(tags, (tuple, list)): # multiple tags
90+
tags = set(tags)
91+
else: # single tag
92+
tags = set((tags,))
9293

9394
def decorator(f):
9495
@wraps(f)

unpythonic/tco.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,11 @@ def s(loop, acc=0, i=0):
599599
return False
600600
assert f() == 15
601601

602-
# setescape point tag can be single value or tuple (tuples OR'd, like isinstance())
603-
@setescape(tag="foo")
602+
# setescape point tags can be single value or tuple (tuples OR'd, like isinstance())
603+
@setescape(tags="foo")
604604
def foo():
605605
@immediate
606-
@setescape(tag="bar")
606+
@setescape(tags="bar")
607607
def bar():
608608
@looped
609609
def s(loop, acc=0, i=0):

0 commit comments

Comments
 (0)