Skip to content

Commit c1eef66

Browse files
committed
nb: init _ to None
1 parent ab53ad8 commit c1eef66

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

unpythonic/syntax/nb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def nb(body, args):
1313
p = args[0] if args else q[print] # custom print function hook
1414
newbody = []
1515
with q as init:
16+
_ = None
1617
theprint = ast_literal[p]
1718
newbody.append(init)
1819
for stmt in body:

unpythonic/syntax/test/test_nb.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
def test():
66
with nb:
7+
assert _ is None
78
2 + 3 # top-level expressions autoprint, and auto-assign result to _
89
assert _ == 5 # ...and only expressions do that, so...
910
_ * 42 # ...here _ still has the value from the first line.
@@ -15,6 +16,7 @@ def test():
1516
print("*** SymPy not installed, skipping symbolic math test ***")
1617
else:
1718
with nb(pprint): # you can specify a custom print function (first positional arg)
19+
assert _ is None
1820
x, y = symbols("x, y")
1921
x * y
2022
assert _ == x * y

0 commit comments

Comments
 (0)