Skip to content

Commit

Permalink
Misc type annotations (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau authored Nov 15, 2024
1 parent 8c8d7d2 commit 8c4901d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from io import FileIO, TextIOWrapper
from logging import StreamHandler
from pathlib import Path
from typing import Optional

import zmq
import zmq.asyncio
Expand Down Expand Up @@ -54,6 +55,7 @@
from .ipkernel import IPythonKernel
from .parentpoller import ParentPollerUnix, ParentPollerWindows
from .shellchannel import ShellChannelThread
from .thread import BaseThread
from .zmqshell import ZMQInteractiveShell

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -142,9 +144,10 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
debug_shell_socket = Any()
stdin_socket = Any()
iopub_socket = Any()
iopub_thread = Any()
control_thread = Any()
shell_channel_thread = Any()

iopub_thread: Optional[IOPubThread] = Instance(IOPubThread, allow_none=True) # type:ignore[assignment]
control_thread: Optional[BaseThread] = Instance(BaseThread, allow_none=True) # type:ignore[assignment]
shell_channel_thread: Optional[BaseThread] = Instance(BaseThread, allow_none=True) # type:ignore[assignment]

_ports = Dict()

Expand Down Expand Up @@ -261,7 +264,7 @@ def _bind_socket(self, s, port):
raise
return None

def write_connection_file(self):
def write_connection_file(self, **kwargs: t.Any) -> None:
"""write connection info to JSON file"""
cf = self.abs_connection_file
connection_info = dict(
Expand Down Expand Up @@ -401,15 +404,15 @@ def close(self):
if self.heartbeat:
self.log.debug("Closing heartbeat channel")
self.heartbeat.context.term()
if self.iopub_thread:
if self.iopub_thread is not None:
self.log.debug("Closing iopub channel")
self.iopub_thread.stop()
self.iopub_thread.close()
if self.control_thread and self.control_thread.is_alive():
if self.control_thread is not None and self.control_thread.is_alive():
self.log.debug("Closing control thread")
self.control_thread.stop()
self.control_thread.join()
if self.shell_channel_thread and self.shell_channel_thread.is_alive():
if self.shell_channel_thread is not None and self.shell_channel_thread.is_alive():
self.log.debug("Closing shell channel thread")
self.shell_channel_thread.stop()
self.shell_channel_thread.join()
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ ignore = [
"G002",
# `open()` should be replaced by `Path.open()`
"PTH123",
# use `X | Y` for type annotations, this does not works for dynamic getting type hints on older python
"UP007",
]
unfixable = [
# Don't touch print statements
Expand Down

0 comments on commit 8c4901d

Please sign in to comment.