Skip to content

Commit 70e895c

Browse files
Carreauianthomas23
authored andcommitted
Misc type annotations (#1294)
1 parent 19f873a commit 70e895c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ipykernel/kernelapp.py

Lines changed: 7 additions & 5 deletions
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
from IPython.core.application import ( # type:ignore[attr-defined]
@@ -141,8 +142,9 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
141142
debug_shell_socket = Any()
142143
stdin_socket = Any()
143144
iopub_socket = Any()
144-
iopub_thread = Any()
145-
control_thread = Any()
145+
146+
iopub_thread: Optional[IOPubThread] = Instance(IOPubThread, allow_none=True) # type:ignore[assignment]
147+
control_thread: Optional[ControlThread] = Instance(ControlThread, allow_none=True) # type:ignore[assignment]
146148

147149
_ports = Dict()
148150

@@ -259,7 +261,7 @@ def _bind_socket(self, s, port):
259261
raise
260262
return None
261263

262-
def write_connection_file(self):
264+
def write_connection_file(self, **kwargs: t.Any) -> None:
263265
"""write connection info to JSON file"""
264266
cf = self.abs_connection_file
265267
connection_info = dict(
@@ -398,11 +400,11 @@ def close(self):
398400
if self.heartbeat:
399401
self.log.debug("Closing heartbeat channel")
400402
self.heartbeat.context.term()
401-
if self.iopub_thread:
403+
if self.iopub_thread is not None:
402404
self.log.debug("Closing iopub channel")
403405
self.iopub_thread.stop()
404406
self.iopub_thread.close()
405-
if self.control_thread and self.control_thread.is_alive():
407+
if self.control_thread is not None and self.control_thread.is_alive():
406408
self.log.debug("Closing control thread")
407409
self.control_thread.stop()
408410
self.control_thread.join()

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ ignore = [
313313
"G002",
314314
# `open()` should be replaced by `Path.open()`
315315
"PTH123",
316+
# use `X | Y` for type annotations, this does not works for dynamic getting type hints on older python
317+
"UP007",
316318
]
317319
unfixable = [
318320
# Don't touch print statements

0 commit comments

Comments
 (0)