Skip to content

Commit 3ab827e

Browse files
committed
"# pragma: no cover" some macro syntax checks
1 parent fe6228a commit 3ab827e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

unpythonic/syntax/tailtools.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def call_cc(tree, **kw):
122122
123123
For more, see the docstring of ``continuations``.
124124
"""
125-
pass
125+
pass # pragma: no cover
126126

127127
# _pcc/cc chaining handler, to be exported to client code via hq[].
128128
#
@@ -258,7 +258,7 @@ def iscallcc(tree):
258258
if type(tree) is Subscript and type(tree.value) is Name and tree.value.id == "call_cc":
259259
if type(tree.slice) is Index:
260260
return True
261-
assert False, "expected single expr, not slice in call_cc[...]"
261+
assert False, "expected single expr, not slice in call_cc[...]" # pragma: no cover
262262
return False
263263
def split_at_callcc(body):
264264
if not body:
@@ -270,7 +270,7 @@ def split_at_callcc(body):
270270
# after is always non-empty here (has at least the explicitified "return")
271271
# ...unless we're at the top level of the "with continuations" block
272272
if not after:
273-
assert False, "call_cc[] cannot appear as the last statement of a 'with continuations' block (no continuation to capture)"
273+
assert False, "call_cc[] cannot appear as the last statement of a 'with continuations' block (no continuation to capture)" # pragma: no cover
274274
# TODO: To support Python's scoping properly in assignments after the `call_cc`,
275275
# TODO: we have to scan `before` for assignments to local variables (stopping at
276276
# TODO: scope boundaries; use `get_names_in_store_context` from our `scoping` module),
@@ -289,42 +289,42 @@ def maybe_starred(expr): # return expr.id or set starget
289289
return [expr.id]
290290
elif type(expr) is Starred:
291291
if type(expr.value) is not Name:
292-
assert False, "call_cc[] starred assignment target must be a bare name"
292+
assert False, "call_cc[] starred assignment target must be a bare name" # pragma: no cover
293293
starget = expr.value.id
294294
return []
295-
assert False, "all call_cc[] assignment targets must be bare names (last one may be starred)"
295+
assert False, "all call_cc[] assignment targets must be bare names (last one may be starred)" # pragma: no cover
296296
# extract the assignment targets (args of the cont)
297297
if type(stmt) is Assign:
298298
if len(stmt.targets) != 1:
299-
assert False, "expected at most one '=' in a call_cc[] statement"
299+
assert False, "expected at most one '=' in a call_cc[] statement" # pragma: no cover
300300
target = stmt.targets[0]
301301
if type(target) in (Tuple, List):
302302
rest, last = target.elts[:-1], target.elts[-1]
303303
# TODO: limitation due to Python's vararg syntax - the "*args" must be after positional args.
304304
if any(type(x) is Starred for x in rest):
305-
assert False, "in call_cc[], only the last assignment target may be starred"
305+
assert False, "in call_cc[], only the last assignment target may be starred" # pragma: no cover
306306
if not all(type(x) is Name for x in rest):
307-
assert False, "all call_cc[] assignment targets must be bare names"
307+
assert False, "all call_cc[] assignment targets must be bare names" # pragma: no cover
308308
targets = [x.id for x in rest] + maybe_starred(last)
309309
else: # single target
310310
targets = maybe_starred(target)
311311
elif type(stmt) is Expr: # no assignment targets, cont takes no args
312312
targets = []
313313
else:
314-
assert False, "call_cc[]: expected an assignment or a bare expr, got {}".format(stmt)
314+
assert False, "call_cc[]: expected an assignment or a bare expr, got {}".format(stmt) # pragma: no cover
315315
# extract the function call(s)
316316
if type(stmt.value) is not Subscript: # both Assign and Expr have a .value
317-
assert False, "expected either an assignment with a call_cc[] expr on RHS, or a bare call_cc[] expr, got {}".format(stmt.value)
317+
assert False, "expected either an assignment with a call_cc[] expr on RHS, or a bare call_cc[] expr, got {}".format(stmt.value) # pragma: no cover
318318
theexpr = stmt.value.slice.value
319319
if not (type(theexpr) in (Call, IfExp) or (type(theexpr) is NameConstant and theexpr.value is None)):
320-
assert False, "the bracketed expression in call_cc[...] must be a function call, an if-expression, or None"
320+
assert False, "the bracketed expression in call_cc[...] must be a function call, an if-expression, or None" # pragma: no cover
321321
def extract_call(tree):
322322
if type(tree) is Call:
323323
return tree
324324
elif type(tree) is NameConstant and tree.value is None:
325325
return None
326326
else:
327-
assert False, "call_cc[...]: expected a function call or None"
327+
assert False, "call_cc[...]: expected a function call or None" # pragma: no cover
328328
if type(theexpr) is IfExp:
329329
condition = theexpr.test
330330
thecall = extract_call(theexpr.body)
@@ -440,11 +440,11 @@ def transform_callcc(owner, body):
440440
@Walker
441441
def check_for_strays(tree, **kw):
442442
if iscallcc(tree):
443-
assert False, "call_cc[...] only allowed at the top level of a def or async def, or at the top level of the block; must appear as an expr or an assignment RHS"
443+
assert False, "call_cc[...] only allowed at the top level of a def or async def, or at the top level of the block; must appear as an expr or an assignment RHS" # pragma: no cover
444444
if type(tree) in (Assign, Expr):
445445
v = tree.value
446446
if type(v) is Call and type(v.func) is Name and v.func.id == "call_cc":
447-
assert False, "call_cc(...) should be call_cc[...] (note brackets; it's a macro)"
447+
assert False, "call_cc(...) should be call_cc[...] (note brackets; it's a macro)" # pragma: no cover
448448
return tree
449449

450450
# -------------------------------------------------------------------------
@@ -456,7 +456,7 @@ def check_for_strays(tree, **kw):
456456
# invocation. (Because call_cc[] internally creates a function and calls it.)
457457
for stmt in block_body:
458458
if type(stmt) is Return:
459-
assert False, "'return' not allowed at the top level of a 'with continuations' block"
459+
assert False, "'return' not allowed at the top level of a 'with continuations' block" # pragma: no cover
460460

461461
# Since we transform **all** returns (even those with an inert data value)
462462
# into tail calls (to cc), we must insert any missing implicit "return"
@@ -540,7 +540,7 @@ def _tco_transform_return(tree, *, known_ecs, transform_retexpr, **kw):
540540
return Expr(value=value) # return ec(...) --> ec(...)
541541
elif treeisec: # TCO the arg of an ec(...) call
542542
if len(tree.args) > 1:
543-
assert False, "expected exactly one argument for escape continuation"
543+
assert False, "expected exactly one argument for escape continuation" # pragma: no cover
544544
tree.args[0] = transform_retexpr(tree.args[0], known_ecs)
545545
return tree
546546

@@ -661,7 +661,7 @@ def transform(tree):
661661
body=transform(tree.values[-1]),
662662
orelse=transform_data(fal))
663663
else: # cannot happen
664-
assert False, "unknown BoolOp type {}".format(tree.op)
664+
assert False, "unknown BoolOp type {}".format(tree.op) # pragma: no cover
665665
else: # optimization: BoolOp, no call or compound in tail position --> treat as single data item
666666
tree = transform_data(tree)
667667
else:

0 commit comments

Comments
 (0)