Skip to content

Commit 79168bb

Browse files
authored
Update typing for traitlets 5.11 (#977)
* Update typing for traitlets 5.11 * fix typing
1 parent 41e0cad commit 79168bb

File tree

11 files changed

+42
-48
lines changed

11 files changed

+42
-48
lines changed

jupyter_client/asynchronous/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def _context_default(self) -> zmq.asyncio.Context:
4848
wait_for_ready = KernelClient._async_wait_for_ready
4949

5050
# The classes to use for the various channels
51-
shell_channel_class = Type(AsyncZMQSocketChannel)
52-
iopub_channel_class = Type(AsyncZMQSocketChannel)
53-
stdin_channel_class = Type(AsyncZMQSocketChannel)
54-
hb_channel_class = Type(HBChannel)
55-
control_channel_class = Type(AsyncZMQSocketChannel)
51+
shell_channel_class = Type(AsyncZMQSocketChannel) # type:ignore[arg-type]
52+
iopub_channel_class = Type(AsyncZMQSocketChannel) # type:ignore[arg-type]
53+
stdin_channel_class = Type(AsyncZMQSocketChannel) # type:ignore[arg-type]
54+
hb_channel_class = Type(HBChannel) # type:ignore[arg-type]
55+
control_channel_class = Type(AsyncZMQSocketChannel) # type:ignore[arg-type]
5656

5757
_recv_reply = KernelClient._async_recv_reply
5858

jupyter_client/blocking/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ class BlockingKernelClient(KernelClient):
4444
wait_for_ready = run_sync(KernelClient._async_wait_for_ready)
4545

4646
# The classes to use for the various channels
47-
shell_channel_class = Type(ZMQSocketChannel)
48-
iopub_channel_class = Type(ZMQSocketChannel)
49-
stdin_channel_class = Type(ZMQSocketChannel)
50-
hb_channel_class = Type(HBChannel)
51-
control_channel_class = Type(ZMQSocketChannel)
47+
shell_channel_class = Type(ZMQSocketChannel) # type:ignore[arg-type]
48+
iopub_channel_class = Type(ZMQSocketChannel) # type:ignore[arg-type]
49+
stdin_channel_class = Type(ZMQSocketChannel) # type:ignore[arg-type]
50+
hb_channel_class = Type(HBChannel) # type:ignore[arg-type]
51+
control_channel_class = Type(ZMQSocketChannel) # type:ignore[arg-type]
5252

5353
_recv_reply = run_sync(KernelClient._async_recv_reply)
5454

jupyter_client/client.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ def shell_channel(self) -> t.Any:
353353
url = self._make_url("shell")
354354
self.log.debug("connecting shell channel to %s", url)
355355
socket = self.connect_shell(identity=self.session.bsession)
356-
self._shell_channel = self.shell_channel_class(
356+
self._shell_channel = self.shell_channel_class( # type:ignore[call-arg,abstract]
357357
socket, self.session, self.ioloop
358-
) # type:ignore[operator]
358+
)
359359
return self._shell_channel
360360

361361
@property
@@ -365,9 +365,9 @@ def iopub_channel(self) -> t.Any:
365365
url = self._make_url("iopub")
366366
self.log.debug("connecting iopub channel to %s", url)
367367
socket = self.connect_iopub()
368-
self._iopub_channel = self.iopub_channel_class(
368+
self._iopub_channel = self.iopub_channel_class( # type:ignore[call-arg,abstract]
369369
socket, self.session, self.ioloop
370-
) # type:ignore[operator]
370+
)
371371
return self._iopub_channel
372372

373373
@property
@@ -377,9 +377,9 @@ def stdin_channel(self) -> t.Any:
377377
url = self._make_url("stdin")
378378
self.log.debug("connecting stdin channel to %s", url)
379379
socket = self.connect_stdin(identity=self.session.bsession)
380-
self._stdin_channel = self.stdin_channel_class(
380+
self._stdin_channel = self.stdin_channel_class( # type:ignore[call-arg,abstract]
381381
socket, self.session, self.ioloop
382-
) # type:ignore[operator]
382+
)
383383
return self._stdin_channel
384384

385385
@property
@@ -388,9 +388,9 @@ def hb_channel(self) -> t.Any:
388388
if self._hb_channel is None:
389389
url = self._make_url("hb")
390390
self.log.debug("connecting heartbeat channel to %s", url)
391-
self._hb_channel = self.hb_channel_class(
391+
self._hb_channel = self.hb_channel_class( # type:ignore[call-arg,abstract]
392392
self.context, self.session, url
393-
) # type:ignore[operator]
393+
)
394394
return self._hb_channel
395395

396396
@property
@@ -400,9 +400,9 @@ def control_channel(self) -> t.Any:
400400
url = self._make_url("control")
401401
self.log.debug("connecting control channel to %s", url)
402402
socket = self.connect_control(identity=self.session.bsession)
403-
self._control_channel = self.control_channel_class(
403+
self._control_channel = self.control_channel_class( # type:ignore[call-arg,abstract]
404404
socket, self.session, self.ioloop
405-
) # type:ignore[operator]
405+
)
406406
return self._control_channel
407407

408408
async def _async_is_alive(self) -> bool:

jupyter_client/consoleapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def init_kernel_manager(self) -> None:
294294

295295
# Create a KernelManager and start a kernel.
296296
try:
297-
self.kernel_manager = self.kernel_manager_class( # type:ignore[operator]
297+
self.kernel_manager = self.kernel_manager_class(
298298
ip=self.ip,
299299
session=self.session,
300300
transport=self.transport,

jupyter_client/kernelspec.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,9 @@ def _get_kernel_spec_by_name(self, kernel_name, resource_dir):
238238
pass
239239
else:
240240
if resource_dir == RESOURCES:
241-
kspec = self.kernel_spec_class(
242-
resource_dir=resource_dir, **get_kernel_dict()
243-
) # type:ignore[operator]
241+
kspec = self.kernel_spec_class(resource_dir=resource_dir, **get_kernel_dict())
244242
if not kspec:
245-
kspec = self.kernel_spec_class.from_resource_dir( # type:ignore[attr-defined]
246-
resource_dir
247-
)
243+
kspec = self.kernel_spec_class.from_resource_dir(resource_dir)
248244

249245
if not KPF.instance(parent=self.parent).is_provisioner_available(kspec):
250246
raise NoSuchKernel(kernel_name)

jupyter_client/kernelspecapp.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import json
66
import os.path
77
import sys
8-
import typing as t
98

109
from jupyter_core.application import JupyterApp, base_aliases, base_flags
1110
from traitlets import Bool, Dict, Instance, List, Unicode
1211
from traitlets.config.application import Application
13-
from traitlets.config.loader import Config
1412

1513
from . import __version__
1614
from .kernelspec import KernelSpecManager
@@ -115,7 +113,7 @@ def _kernel_name_default(self):
115113
"name": "InstallKernelSpec.kernel_name",
116114
"prefix": "InstallKernelSpec.prefix",
117115
}
118-
aliases.update(base_aliases) # type:ignore[arg-type]
116+
aliases.update(base_aliases)
119117

120118
flags = {
121119
"user": (
@@ -185,7 +183,7 @@ def _kernel_spec_manager_default(self):
185183
flags = {
186184
"f": ({"RemoveKernelSpec": {"force": True}}, force.help),
187185
}
188-
flags.update(JupyterApp.flags) # type:ignore[has-type]
186+
flags.update(JupyterApp.flags)
189187

190188
def parse_command_line(self, argv):
191189
"""Parse the command line args."""
@@ -275,7 +273,7 @@ def start(self): # pragma: no cover
275273
file=sys.stderr,
276274
)
277275
self.exit(1)
278-
self.exit(e)
276+
self.exit(e) # type:ignore[arg-type]
279277

280278

281279
class ListProvisioners(JupyterApp):
@@ -321,10 +319,8 @@ class KernelSpecApp(Application):
321319
}
322320
)
323321

324-
aliases: t.Dict[t.Union[str, t.Tuple[str, ...]], t.Union[str, t.Tuple[str, str]]] = {}
325-
flags: t.Dict[
326-
t.Union[str, t.Tuple[str, ...]], t.Tuple[t.Union[t.Dict[str, t.Any], Config], str]
327-
] = {}
322+
aliases = {}
323+
flags = {}
328324

329325
def start(self):
330326
"""Start the application."""

jupyter_client/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _kernel_spec_manager_default(self) -> kernelspec.KernelSpecManager:
150150
return kernelspec.KernelSpecManager(data_dir=self.data_dir)
151151

152152
@observe("kernel_spec_manager")
153-
@observe_compat # type:ignore[misc]
153+
@observe_compat
154154
def _kernel_spec_manager_changed(self, change: t.Dict[str, Instance]) -> None:
155155
self._kernel_spec = None
156156

jupyter_client/provisioning/local_provisioner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import signal
77
import sys
8-
from typing import Any, Dict, List, Optional
8+
from typing import TYPE_CHECKING, Any, Dict, List, Optional
99

1010
from ..connect import KernelConnectionInfo, LocalPortCache
1111
from ..launcher import launch_kernel
@@ -150,6 +150,8 @@ async def cleanup(self, restart: bool = False) -> None:
150150
self.connection_info['control_port'],
151151
)
152152
for port in ports:
153+
if TYPE_CHECKING:
154+
assert isinstance(port, int)
153155
lpc.return_port(port)
154156

155157
async def pre_launch(self, **kwargs: Any) -> Dict[str, Any]:

jupyter_client/threaded.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ def stop_channels(self) -> None:
333333
if self.ioloop_thread and self.ioloop_thread.is_alive():
334334
self.ioloop_thread.stop()
335335

336-
iopub_channel_class = Type(ThreadedZMQSocketChannel)
337-
shell_channel_class = Type(ThreadedZMQSocketChannel)
338-
stdin_channel_class = Type(ThreadedZMQSocketChannel)
339-
hb_channel_class = Type(HBChannel)
340-
control_channel_class = Type(ThreadedZMQSocketChannel)
336+
iopub_channel_class = Type(ThreadedZMQSocketChannel) # type:ignore[arg-type]
337+
shell_channel_class = Type(ThreadedZMQSocketChannel) # type:ignore[arg-type]
338+
stdin_channel_class = Type(ThreadedZMQSocketChannel) # type:ignore[arg-type]
339+
hb_channel_class = Type(HBChannel) # type:ignore[arg-type]
340+
control_channel_class = Type(ThreadedZMQSocketChannel) # type:ignore[arg-type]
341341

342342
def is_alive(self) -> bool:
343343
"""Is the kernel process still running?"""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ nowarn = "test -W default {args}"
103103

104104
[tool.hatch.envs.typing]
105105
features = ["test"]
106-
dependencies = ["mypy>=1.5.1", "traitlets>=5.10.1"]
106+
dependencies = ["mypy>=1.5.1", "traitlets>=5.11.2", "jupyter_core>=5.3.2"]
107107
[tool.hatch.envs.typing.scripts]
108108
test = "mypy --install-types --non-interactive {args:.}"
109109

0 commit comments

Comments
 (0)