Skip to content

Commit 8c4901d

Browse files
authored
Misc type annotations (#1294)
1 parent 8c8d7d2 commit 8c4901d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Diff for: ipykernel/kernelapp.py

+10-7
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 typing import Optional
1920

2021
import zmq
2122
import zmq.asyncio
@@ -54,6 +55,7 @@
5455
from .ipkernel import IPythonKernel
5556
from .parentpoller import ParentPollerUnix, ParentPollerWindows
5657
from .shellchannel import ShellChannelThread
58+
from .thread import BaseThread
5759
from .zmqshell import ZMQInteractiveShell
5860

5961
# -----------------------------------------------------------------------------
@@ -142,9 +144,10 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
142144
debug_shell_socket = Any()
143145
stdin_socket = Any()
144146
iopub_socket = Any()
145-
iopub_thread = Any()
146-
control_thread = Any()
147-
shell_channel_thread = Any()
147+
148+
iopub_thread: Optional[IOPubThread] = Instance(IOPubThread, allow_none=True) # type:ignore[assignment]
149+
control_thread: Optional[BaseThread] = Instance(BaseThread, allow_none=True) # type:ignore[assignment]
150+
shell_channel_thread: Optional[BaseThread] = Instance(BaseThread, allow_none=True) # type:ignore[assignment]
148151

149152
_ports = Dict()
150153

@@ -261,7 +264,7 @@ def _bind_socket(self, s, port):
261264
raise
262265
return None
263266

264-
def write_connection_file(self):
267+
def write_connection_file(self, **kwargs: t.Any) -> None:
265268
"""write connection info to JSON file"""
266269
cf = self.abs_connection_file
267270
connection_info = dict(
@@ -401,15 +404,15 @@ def close(self):
401404
if self.heartbeat:
402405
self.log.debug("Closing heartbeat channel")
403406
self.heartbeat.context.term()
404-
if self.iopub_thread:
407+
if self.iopub_thread is not None:
405408
self.log.debug("Closing iopub channel")
406409
self.iopub_thread.stop()
407410
self.iopub_thread.close()
408-
if self.control_thread and self.control_thread.is_alive():
411+
if self.control_thread is not None and self.control_thread.is_alive():
409412
self.log.debug("Closing control thread")
410413
self.control_thread.stop()
411414
self.control_thread.join()
412-
if self.shell_channel_thread and self.shell_channel_thread.is_alive():
415+
if self.shell_channel_thread is not None and self.shell_channel_thread.is_alive():
413416
self.log.debug("Closing shell channel thread")
414417
self.shell_channel_thread.stop()
415418
self.shell_channel_thread.join()

Diff for: pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ ignore = [
276276
"G002",
277277
# `open()` should be replaced by `Path.open()`
278278
"PTH123",
279+
# use `X | Y` for type annotations, this does not works for dynamic getting type hints on older python
280+
"UP007",
279281
]
280282
unfixable = [
281283
# Don't touch print statements

0 commit comments

Comments
 (0)