|
15 | 15 |
|
16 | 16 | from ..dynassign import dyn |
17 | 17 | from ..env import env |
18 | | -from ..misc import callsite_filename |
| 18 | +from ..misc import callsite_filename, namelambda |
19 | 19 | from ..conditions import cerror, handlers, restarts, invoke |
20 | 20 | from ..collections import unbox |
21 | 21 | from ..symbol import sym |
@@ -146,7 +146,8 @@ def unpythonic_assert(sourcecode, func, *, filename, lineno, message=None): |
146 | 146 | # we send to `func` as its argument. A `the[]` is also implicitly injected |
147 | 147 | # by the comparison destructuring mechanism. |
148 | 148 | 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 |
150 | 151 | if e.captured_values: |
151 | 152 | # Convenience for testing/debugging macro code: |
152 | 153 | # |
@@ -481,8 +482,12 @@ def test_expr(tree): |
481 | 482 | # |
482 | 483 | # Also, we need the lambda for passing in the value capture environment |
483 | 484 | # 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 |
486 | 491 |
|
487 | 492 | return q[(a[asserter])(u[sourcecode], |
488 | 493 | a[func_tree], |
|
0 commit comments