Skip to content

Commit 59be6e7

Browse files
committed
Misc cleanup and types updates
1 parent 314cc49 commit 59be6e7

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

ipykernel/kernelapp.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from io import FileIO, TextIOWrapper
1717
from logging import StreamHandler
1818
from pathlib import Path
19+
from threading import Thread
1920

2021
import zmq
2122
import zmq.asyncio
@@ -142,9 +143,9 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
142143
debug_shell_socket = Any()
143144
stdin_socket = Any()
144145
iopub_socket = Any()
145-
iopub_thread = Any()
146-
control_thread = Any()
147-
shell_channel_thread = Any()
146+
iopub_thread: Thread
147+
control_thread: Thread
148+
shell_channel_thread: Thread
148149

149150
_ports = Dict()
150151

ipykernel/kernelbase.py

+49-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import queue
1212
import sys
1313
import threading
14+
from threading import Thread
1415
import time
1516
import typing as t
1617
import uuid
@@ -95,17 +96,16 @@ class Kernel(SingletonConfigurable):
9596
implementation_version: str
9697
banner: str
9798

98-
_is_test = Bool(False)
99+
_is_test: bool
99100

100101
control_socket = Instance(zmq.asyncio.Socket, allow_none=True)
101102
control_tasks: t.Any = List()
102103

103104
debug_shell_socket = Any()
105+
control_thread: Thread
106+
shell_channel_thread: Thread
104107

105-
control_thread = Any()
106-
shell_channel_thread = Any()
107108
iopub_socket = Any()
108-
iopub_thread = Any()
109109
stdin_socket = Any()
110110
log: logging.Logger = Instance(logging.Logger, allow_none=True) # type:ignore[assignment]
111111

@@ -217,6 +217,9 @@ def _parent_header(self):
217217
"shutdown_request",
218218
"is_complete_request",
219219
"interrupt_request",
220+
# I have the impression that there is amix/match debug_request and do_debug_request
221+
# former was from ipyparallel but is marked as deprecated, but now call do_debug_request
222+
# "do_debug_request"
220223
# deprecated:
221224
"apply_request",
222225
]
@@ -258,6 +261,17 @@ def __init__(self, **kwargs):
258261
self.do_execute, ["cell_meta", "cell_id"]
259262
)
260263

264+
if not inspect.iscoroutinefunction(self.do_debug_request):
265+
# warning at init time, as we want to warn early enough, even if the
266+
# function is not called
267+
warnings.warn(
268+
"`do_debug_request` will be required to be a coroutine "
269+
"functions in the future. coroutine functions have ben supported "
270+
"since ipykernel 6.0 (2021)",
271+
DeprecationWarning,
272+
stacklevel=2,
273+
)
274+
261275
async def process_control(self):
262276
try:
263277
while True:
@@ -1008,12 +1022,29 @@ def do_is_complete(self, code):
10081022

10091023
async def debug_request(self, socket, ident, parent):
10101024
"""Handle a debug request."""
1025+
# If this is incorrect, remove `debug_request` from the deprecated message types
1026+
# at the beginning of this class
1027+
self.log.warning(
1028+
"abort_request is deprecated in kernel_base since ipykernel 6.10"
1029+
" (2022). It is only part of IPython parallel. Did you mean do_debug_request ?",
1030+
DeprecationWarning,
1031+
)
10111032
if not self.session:
10121033
return
10131034
content = parent["content"]
1014-
reply_content = self.do_debug_request(content)
1015-
if inspect.isawaitable(reply_content):
1016-
reply_content = await reply_content
1035+
if not inspect.iscoroutinefunction(self.do_debug_request):
1036+
# repeat the warning at run
1037+
reply_content = self.do_debug_request(content)
1038+
warnings.warn(
1039+
"`do_debug_request` will be required to be a coroutine "
1040+
"functions in the future. coroutine functions have ben supported "
1041+
"since ipykernel 6.0 (2021)",
1042+
DeprecationWarning,
1043+
)
1044+
if inspect.isawaitable(reply_content):
1045+
reply_content = await reply_content
1046+
else:
1047+
reply_content = await self.do_debug_request(content)
10171048
reply_content = json_clean(reply_content)
10181049
reply_msg = self.session.send(socket, "debug_reply", reply_content, parent, ident)
10191050
self.log.debug("%s", reply_msg)
@@ -1132,7 +1163,11 @@ async def list_subshell_request(self, socket, ident, parent) -> None:
11321163

11331164
async def apply_request(self, socket, ident, parent): # pragma: no cover
11341165
"""Handle an apply request."""
1135-
self.log.warning("apply_request is deprecated in kernel_base, moving to ipyparallel.")
1166+
self.log.warning(
1167+
"apply_request is deprecated in kernel_base since"
1168+
" IPykernel 6.10 (2022) , moving to ipyparallel.",
1169+
DeprecationWarning,
1170+
)
11361171
try:
11371172
content = parent["content"]
11381173
bufs = parent["buffers"]
@@ -1175,7 +1210,9 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
11751210
async def abort_request(self, socket, ident, parent): # pragma: no cover
11761211
"""abort a specific msg by id"""
11771212
self.log.warning(
1178-
"abort_request is deprecated in kernel_base. It is only part of IPython parallel"
1213+
"abort_request is deprecated in kernel_base since ipykernel 6.10"
1214+
" (2022). It is only part of IPython parallel",
1215+
DeprecationWarning,
11791216
)
11801217
msg_ids = parent["content"].get("msg_ids", None)
11811218
if isinstance(msg_ids, str):
@@ -1194,7 +1231,9 @@ async def abort_request(self, socket, ident, parent): # pragma: no cover
11941231
async def clear_request(self, socket, idents, parent): # pragma: no cover
11951232
"""Clear our namespace."""
11961233
self.log.warning(
1197-
"clear_request is deprecated in kernel_base. It is only part of IPython parallel"
1234+
"clear_request is deprecated in kernel_base since IPykernel 6.10"
1235+
" (2022). It is only part of IPython parallel",
1236+
DeprecationWarning,
11981237
)
11991238
content = self.do_clear()
12001239
if self.session:

0 commit comments

Comments
 (0)