Skip to content

Commit 9461094

Browse files
committed
improve naming for more readable stack trace
1 parent 5f19cf6 commit 9461094

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

unpythonic/syntax/testingtools.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from ..dynassign import dyn
1717
from ..env import env
18-
from ..misc import callsite_filename
18+
from ..misc import callsite_filename, namelambda
1919
from ..conditions import cerror, handlers, restarts, invoke
2020
from ..collections import unbox
2121
from ..symbol import sym
@@ -146,7 +146,8 @@ def unpythonic_assert(sourcecode, func, *, filename, lineno, message=None):
146146
# we send to `func` as its argument. A `the[]` is also implicitly injected
147147
# by the comparison destructuring mechanism.
148148
e = env(captured_values=[])
149-
mode, test_result = _observe(lambda: func(e)) # <-- run the actual expr being asserted
149+
testexpr = func # descriptive name for stack trace; if you change this, change also in `test_expr`.
150+
mode, test_result = _observe(thunk=(lambda: testexpr(e))) # <-- run the actual expr being asserted
150151
if e.captured_values:
151152
# Convenience for testing/debugging macro code:
152153
#
@@ -481,8 +482,12 @@ def test_expr(tree):
481482
#
482483
# Also, we need the lambda for passing in the value capture environment
483484
# for the `the[]` mark, anyway.
484-
func_tree = q[lambda _: a[tree]] # create the function that takes in the env
485-
func_tree.args.args[0] = arg(arg=envname) # inject the gensymmed parameter name
485+
#
486+
# We name it `testexpr` to make the stack trace more understandable.
487+
# If you change the name, change it also in `unpythonic_assert`.
488+
thelambda = q[lambda _: a[tree]]
489+
thelambda.args.args[0] = arg(arg=envname) # inject the gensymmed parameter name
490+
func_tree = q[h[namelambda]("testexpr")(a[thelambda])] # create the function that takes in the env
486491

487492
return q[(a[asserter])(u[sourcecode],
488493
a[func_tree],

0 commit comments

Comments
 (0)