Skip to content

Commit 3c4b5bf

Browse files
authored
Update typing for traitlets 5.13 (#1162)
1 parent 76aca77 commit 3c4b5bf

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

ipykernel/inprocess/ipkernel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def _input_request(self, prompt, ident, parent, password=False):
104104
assert self.session is not None
105105
msg = self.session.msg("input_request", content, parent)
106106
for frontend in self.frontends:
107+
assert frontend is not None
107108
if frontend.session.session == parent["header"]["session"]:
108109
frontend.stdin_channel.call_handlers(msg)
109110
break
@@ -138,6 +139,7 @@ def _io_dispatch(self, change):
138139
assert self.session is not None
139140
ident, msg = self.session.recv(self.iopub_socket.io_thread.socket, copy=False)
140141
for frontend in self.frontends:
142+
assert frontend is not None
141143
frontend.iopub_channel.call_handlers(msg)
142144

143145
# ------ Trait initializers -----------------------------------------------

ipykernel/kernelapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def log_connection_info(self):
443443
self.log.info(line)
444444
# also raw print to the terminal if no parent_handle (`ipython kernel`)
445445
# unless log-level is CRITICAL (--quiet)
446-
if not self.parent_handle and int(self.log_level) < logging.CRITICAL:
446+
if not self.parent_handle and int(self.log_level) < logging.CRITICAL: # type:ignore[call-overload]
447447
print(_ctrl_c_message, file=sys.__stdout__)
448448
for line in lines:
449449
print(line, file=sys.__stdout__)
@@ -700,7 +700,7 @@ def initialize(self, argv=None):
700700
except Exception:
701701
# Catch exception when initializing signal fails, eg when running the
702702
# kernel on a separate thread
703-
if int(self.log_level) < logging.CRITICAL:
703+
if int(self.log_level) < logging.CRITICAL: # type:ignore[call-overload]
704704
self.log.error("Unable to initialize signal:", exc_info=True)
705705
self.init_kernel()
706706
# shell init steps

ipykernel/kernelbase.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Copyright (c) IPython Development Team.
44
# Distributed under the terms of the Modified BSD License.
5+
from __future__ import annotations
56

67
import asyncio
78
import concurrent.futures
@@ -80,7 +81,7 @@ class Kernel(SingletonConfigurable):
8081
# attribute to override with a GUI
8182
eventloop = Any(None)
8283

83-
processes: t.Dict[str, psutil.Process] = {}
84+
processes: dict[str, psutil.Process] = {}
8485

8586
@observe("eventloop")
8687
def _update_eventloop(self, change):
@@ -93,7 +94,7 @@ def _update_eventloop(self, change):
9394
profile_dir = Instance("IPython.core.profiledir.ProfileDir", allow_none=True)
9495
shell_stream = Instance(ZMQStream, allow_none=True)
9596

96-
shell_streams = List(
97+
shell_streams: List[t.Any] = List(
9798
help="""Deprecated shell_streams alias. Use shell_stream
9899
99100
.. versionchanged:: 6.0
@@ -153,10 +154,10 @@ def _default_ident(self):
153154

154155
# This should be overridden by wrapper kernels that implement any real
155156
# language.
156-
language_info: t.Dict[str, object] = {}
157+
language_info: dict[str, object] = {}
157158

158159
# any links that should go in the help menu
159-
help_links = List()
160+
help_links: List[dict[str, str]] = List()
160161

161162
# Experimental option to break in non-user code.
162163
# The ipykernel source is in the call stack, so the user
@@ -180,7 +181,7 @@ def _default_ident(self):
180181

181182
# track associations with current request
182183
_allow_stdin = Bool(False)
183-
_parents = Dict({"shell": {}, "control": {}})
184+
_parents: Dict[str, t.Any] = Dict({"shell": {}, "control": {}})
184185
_parent_ident = Dict({"shell": b"", "control": b""})
185186

186187
@property
@@ -291,7 +292,7 @@ async def poll_control_queue(self):
291292

292293
async def _flush_control_queue(self):
293294
"""Flush the control queue, wait for processing of any pending messages"""
294-
tracer_future: t.Union[concurrent.futures.Future[object], asyncio.Future[object]]
295+
tracer_future: concurrent.futures.Future[object] | asyncio.Future[object]
295296
if self.control_thread:
296297
control_loop = self.control_thread.io_loop
297298
# concurrent.futures.Futures are threadsafe
@@ -945,7 +946,7 @@ async def interrupt_request(self, stream, ident, parent):
945946
"""Handle an interrupt request."""
946947
if not self.session:
947948
return
948-
content: t.Dict[str, t.Any] = {"status": "ok"}
949+
content: dict[str, t.Any] = {"status": "ok"}
949950
try:
950951
self._send_interrupt_children()
951952
except OSError as err:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ matrix.qt.features = [
112112

113113
[tool.hatch.envs.typing]
114114
features = ["test"]
115-
dependencies = ["mypy>=1.6.0", "traitlets>=5.12.0", "ipython>=8.16.1", "jupyter_client>=8.5"]
115+
dependencies = ["mypy>=1.6.0", "traitlets>=5.13.0", "ipython>=8.16.1", "jupyter_client>=8.5"]
116116
[tool.hatch.envs.typing.scripts]
117117
test = "mypy --install-types --non-interactive {args}"
118118

0 commit comments

Comments
 (0)