Skip to content

Commit 4af29c1

Browse files
committed
Remove unused variables
Unused variables are a code smell. Removing them make it clearer we expect the functions called to be called for their side-effects. Part of the #717 PR-group.
1 parent b2f1a79 commit 4af29c1

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

ipykernel/kernelbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ def _input_request(self, prompt, ident, parent, password=False):
10241024
except KeyboardInterrupt:
10251025
# re-raise KeyboardInterrupt, to truncate traceback
10261026
raise KeyboardInterrupt("Interrupted by user") from None
1027-
except Exception as e:
1027+
except Exception:
10281028
self.log.warning("Invalid Message:", exc_info=True)
10291029

10301030
try:

ipykernel/tests/test_embed_kernel.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,18 @@ def test_embed_kernel_basic():
9494

9595
with setup_kernel(cmd) as client:
9696
# oinfo a (int)
97-
msg_id = client.inspect('a')
97+
client.inspect("a")
9898
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
9999
content = msg['content']
100100
assert content['found']
101101

102-
msg_id = client.execute("c=a*2")
102+
client.execute("c=a*2")
103103
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
104104
content = msg['content']
105105
assert content['status'] == 'ok'
106106

107107
# oinfo c (should be 10)
108-
msg_id = client.inspect('c')
108+
client.inspect("c")
109109
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
110110
content = msg['content']
111111
assert content['found']
@@ -128,23 +128,23 @@ def test_embed_kernel_namespace():
128128

129129
with setup_kernel(cmd) as client:
130130
# oinfo a (int)
131-
msg_id = client.inspect('a')
131+
client.inspect("a")
132132
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
133133
content = msg['content']
134134
assert content['found']
135135
text = content['data']['text/plain']
136136
assert '5' in text
137137

138138
# oinfo b (str)
139-
msg_id = client.inspect('b')
139+
client.inspect("b")
140140
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
141141
content = msg['content']
142142
assert content['found']
143143
text = content['data']['text/plain']
144144
assert 'hi there' in text
145145

146146
# oinfo c (undefined)
147-
msg_id = client.inspect('c')
147+
client.inspect("c")
148148
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
149149
content = msg['content']
150150
assert not content['found']
@@ -167,7 +167,7 @@ def test_embed_kernel_reentrant():
167167

168168
with setup_kernel(cmd) as client:
169169
for i in range(5):
170-
msg_id = client.inspect('count')
170+
client.inspect("count")
171171
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
172172
content = msg['content']
173173
assert content['found']

ipykernel/tests/test_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def test_control_thread_priority():
447447
control_msg_ids.append(msg["header"]["msg_id"])
448448

449449
# finally, collect the replies on both channels for comparison
450-
sleep_reply = get_reply(kc, sleep_msg_id)
450+
get_reply(kc, sleep_msg_id)
451451
shell_replies = []
452452
for msg_id in shell_msg_ids:
453453
shell_replies.append(get_reply(kc, msg_id))

ipykernel/tests/test_kernelspec.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ def test_write_kernel_spec_path():
8989
def test_install_kernelspec():
9090

9191
path = tempfile.mkdtemp()
92-
try:
93-
test = InstallIPythonKernelSpecApp.launch_instance(argv=['--prefix', path])
94-
assert_is_spec(os.path.join(
95-
path, 'share', 'jupyter', 'kernels', KERNEL_NAME))
92+
try:
93+
InstallIPythonKernelSpecApp.launch_instance(argv=["--prefix", path])
94+
assert_is_spec(os.path.join(path, "share", "jupyter", "kernels", KERNEL_NAME))
9695
finally:
9796
shutil.rmtree(path)
9897

ipykernel/tests/test_message_spec.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,15 @@ def test_execute_inc():
322322
"""execute request should increment execution_count"""
323323
flush_channels()
324324

325-
msg_id, reply = execute(code='x=1')
326-
count = reply['execution_count']
325+
_, reply = execute(code="x=1")
326+
count = reply["execution_count"]
327327

328328
flush_channels()
329329

330-
msg_id, reply = execute(code='x=2')
331-
count_2 = reply['execution_count']
332-
assert count_2 == count+1
330+
_, reply = execute(code="x=2")
331+
count_2 = reply["execution_count"]
332+
assert count_2 == count + 1
333+
333334

334335
def test_execute_stop_on_error():
335336
"""execute request should not abort execution queue with stop_on_error False"""
@@ -342,15 +343,15 @@ def test_execute_stop_on_error():
342343
'raise ValueError',
343344
])
344345
KC.execute(code=fail)
345-
msg_id = KC.execute(code='print("Hello")')
346+
KC.execute(code='print("Hello")')
346347
KC.get_shell_msg(timeout=TIMEOUT)
347348
reply = KC.get_shell_msg(timeout=TIMEOUT)
348349
assert reply['content']['status'] == 'aborted'
349350

350351
flush_channels()
351352

352353
KC.execute(code=fail, stop_on_error=False)
353-
msg_id = KC.execute(code='print("Hello")')
354+
KC.execute(code='print("Hello")')
354355
KC.get_shell_msg(timeout=TIMEOUT)
355356
reply = KC.get_shell_msg(timeout=TIMEOUT)
356357
assert reply['content']['status'] == 'ok'
@@ -519,8 +520,8 @@ def test_is_complete():
519520
def test_history_range():
520521
flush_channels()
521522

522-
msg_id_exec = KC.execute(code='x=1', store_history = True)
523-
reply_exec = KC.get_shell_msg(timeout=TIMEOUT)
523+
KC.execute(code="x=1", store_history=True)
524+
KC.get_shell_msg(timeout=TIMEOUT)
524525

525526
msg_id = KC.history(hist_access_type = 'range', raw = True, output = True, start = 1, stop = 2, session = 0)
526527
reply = get_reply(KC, msg_id, TIMEOUT)
@@ -531,8 +532,8 @@ def test_history_range():
531532
def test_history_tail():
532533
flush_channels()
533534

534-
msg_id_exec = KC.execute(code='x=1', store_history = True)
535-
reply_exec = KC.get_shell_msg(timeout=TIMEOUT)
535+
KC.execute(code="x=1", store_history=True)
536+
KC.get_shell_msg(timeout=TIMEOUT)
536537

537538
msg_id = KC.history(hist_access_type = 'tail', raw = True, output = True, n = 1, session = 0)
538539
reply = get_reply(KC, msg_id, TIMEOUT)
@@ -543,8 +544,8 @@ def test_history_tail():
543544
def test_history_search():
544545
flush_channels()
545546

546-
msg_id_exec = KC.execute(code='x=1', store_history = True)
547-
reply_exec = KC.get_shell_msg(timeout=TIMEOUT)
547+
KC.execute(code="x=1", store_history=True)
548+
KC.get_shell_msg(timeout=TIMEOUT)
548549

549550
msg_id = KC.history(hist_access_type = 'search', raw = True, output = True, n = 1, pattern = '*', session = 0)
550551
reply = get_reply(KC, msg_id, TIMEOUT)

ipykernel/tests/test_start_kernel.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ def test_ipython_start_kernel_userns():
1111
'start_kernel(user_ns=ns)')
1212

1313
with setup_kernel(cmd) as client:
14-
msg_id = client.inspect('tre')
14+
client.inspect("tre")
1515
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
1616
content = msg['content']
1717
assert content['found']
1818
text = content['data']['text/plain']
1919
assert '123' in text
2020

2121
# user_module should be an instance of DummyMod
22-
msg_id = client.execute("usermod = get_ipython().user_module")
22+
client.execute("usermod = get_ipython().user_module")
2323
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
24-
content = msg['content']
25-
assert content['status'] == 'ok'
26-
msg_id = client.inspect('usermod')
24+
content = msg["content"]
25+
assert content["status"] == "ok"
26+
client.inspect("usermod")
2727
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
2828
content = msg['content']
2929
assert content['found']
@@ -39,11 +39,11 @@ def test_ipython_start_kernel_no_userns():
3939

4040
with setup_kernel(cmd) as client:
4141
# user_module should not be an instance of DummyMod
42-
msg_id = client.execute("usermod = get_ipython().user_module")
42+
client.execute("usermod = get_ipython().user_module")
4343
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
44-
content = msg['content']
45-
assert content['status'] == 'ok'
46-
msg_id = client.inspect('usermod')
44+
content = msg["content"]
45+
assert content["status"] == "ok"
46+
client.inspect("usermod")
4747
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
4848
content = msg['content']
4949
assert content['found']

0 commit comments

Comments
 (0)