Skip to content

Commit 18f0d0c

Browse files
committed
Bump mypy to 1.16.1
1 parent 524040a commit 18f0d0c

File tree

8 files changed

+54
-43
lines changed

8 files changed

+54
-43
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ repos:
4040
types_or: [yaml, html, json]
4141

4242
- repo: https://github.com/pre-commit/mirrors-mypy
43-
rev: "v1.8.0"
43+
rev: "v1.16.1"
4444
hooks:
4545
- id: mypy
4646
files: ipykernel

ipykernel/comm/comm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
4949
class Comm(BaseComm, traitlets.config.LoggingConfigurable):
5050
"""Class for communicating between a Frontend and a Kernel"""
5151

52-
kernel = Instance("ipykernel.kernelbase.Kernel", allow_none=True) # type:ignore[assignment]
52+
kernel = Instance("ipykernel.kernelbase.Kernel", allow_none=True)
5353
comm_id = Unicode()
5454
primary = Bool(True, help="Am I the primary or secondary Comm?")
5555

ipykernel/inprocess/blocking.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def call_handlers(self, msg):
6969
_raw_input = self.client.kernel._sys_raw_input
7070
prompt = msg["content"]["prompt"]
7171
print(prompt, end="", file=sys.__stdout__)
72+
assert sys.__stdout__ is not None
7273
sys.__stdout__.flush()
7374
self.client.input(_raw_input())
7475

@@ -77,9 +78,9 @@ class BlockingInProcessKernelClient(InProcessKernelClient):
7778
"""A blocking in-process kernel client."""
7879

7980
# The classes to use for the various channels.
80-
shell_channel_class = Type(BlockingInProcessChannel) # type:ignore[arg-type]
81-
iopub_channel_class = Type(BlockingInProcessChannel) # type:ignore[arg-type]
82-
stdin_channel_class = Type(BlockingInProcessStdInChannel) # type:ignore[arg-type]
81+
shell_channel_class = Type(BlockingInProcessChannel)
82+
iopub_channel_class = Type(BlockingInProcessChannel)
83+
stdin_channel_class = Type(BlockingInProcessStdInChannel)
8384

8485
def wait_for_ready(self):
8586
"""Wait for kernel info reply on shell channel."""

ipykernel/inprocess/client.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# -----------------------------------------------------------------------------
1313

1414
import asyncio
15+
from typing import Any
1516

1617
from jupyter_client.client import KernelClient
1718
from jupyter_client.clientabc import KernelClientABC
@@ -39,11 +40,11 @@ class InProcessKernelClient(KernelClient):
3940
"""
4041

4142
# The classes to use for the various channels.
42-
shell_channel_class = Type(InProcessChannel) # type:ignore[arg-type]
43-
iopub_channel_class = Type(InProcessChannel) # type:ignore[arg-type]
44-
stdin_channel_class = Type(InProcessChannel) # type:ignore[arg-type]
45-
control_channel_class = Type(InProcessChannel) # type:ignore[arg-type]
46-
hb_channel_class = Type(InProcessHBChannel) # type:ignore[arg-type]
43+
shell_channel_class = Type(InProcessChannel) # type:ignore[assignment]
44+
iopub_channel_class = Type(InProcessChannel) # type:ignore[assignment]
45+
stdin_channel_class = Type(InProcessChannel) # type:ignore[assignment]
46+
control_channel_class = Type(InProcessChannel) # type:ignore[assignment]
47+
hb_channel_class = Type(InProcessHBChannel) # type:ignore[assignment]
4748

4849
kernel = Instance("ipykernel.inprocess.ipkernel.InProcessKernel", allow_none=True)
4950

@@ -57,9 +58,9 @@ def _default_blocking_class(self):
5758

5859
return BlockingInProcessKernelClient
5960

60-
def get_connection_info(self):
61+
def get_connection_info(self, session: bool = False) -> dict[str, int | str | bytes]:
6162
"""Get the connection info for the client."""
62-
d = super().get_connection_info()
63+
d = super().get_connection_info(session=session)
6364
d["kernel"] = self.kernel # type:ignore[assignment]
6465
return d
6566

@@ -72,39 +73,45 @@ def start_channels(self, *args, **kwargs):
7273
@property
7374
def shell_channel(self):
7475
if self._shell_channel is None:
75-
self._shell_channel = self.shell_channel_class(self) # type:ignore[abstract,call-arg]
76+
self._shell_channel = self.shell_channel_class(self)
7677
return self._shell_channel
7778

7879
@property
7980
def iopub_channel(self):
8081
if self._iopub_channel is None:
81-
self._iopub_channel = self.iopub_channel_class(self) # type:ignore[abstract,call-arg]
82+
self._iopub_channel = self.iopub_channel_class(self)
8283
return self._iopub_channel
8384

8485
@property
8586
def stdin_channel(self):
8687
if self._stdin_channel is None:
87-
self._stdin_channel = self.stdin_channel_class(self) # type:ignore[abstract,call-arg]
88+
self._stdin_channel = self.stdin_channel_class(self)
8889
return self._stdin_channel
8990

9091
@property
9192
def control_channel(self):
9293
if self._control_channel is None:
93-
self._control_channel = self.control_channel_class(self) # type:ignore[abstract,call-arg]
94+
self._control_channel = self.control_channel_class(self)
9495
return self._control_channel
9596

9697
@property
9798
def hb_channel(self):
9899
if self._hb_channel is None:
99-
self._hb_channel = self.hb_channel_class(self) # type:ignore[abstract,call-arg]
100+
self._hb_channel = self.hb_channel_class(self)
100101
return self._hb_channel
101102

102103
# Methods for sending specific messages
103104
# -------------------------------------
104105

105106
def execute(
106-
self, code, silent=False, store_history=True, user_expressions=None, allow_stdin=None
107-
):
107+
self,
108+
code: str,
109+
silent: bool = False,
110+
store_history: bool = True,
111+
user_expressions: dict[str, Any] | None = None,
112+
allow_stdin: bool | None = None,
113+
stop_on_error: bool = True,
114+
) -> str:
108115
"""Execute code on the client."""
109116
if allow_stdin is None:
110117
allow_stdin = self.allow_stdin
@@ -117,7 +124,9 @@ def execute(
117124
)
118125
msg = self.session.msg("execute_request", content)
119126
self._dispatch_to_kernel(msg)
120-
return msg["header"]["msg_id"]
127+
res = msg["header"]["msg_id"]
128+
assert isinstance(res, str)
129+
return res
121130

122131
def complete(self, code, cursor_pos=None):
123132
"""Get code completion."""

ipykernel/inprocess/ipkernel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InProcessKernel(IPythonKernel):
5151
_underlying_iopub_socket = Instance(DummySocket, ())
5252
iopub_thread: IOPubThread = Instance(IOPubThread) # type:ignore[assignment]
5353

54-
shell_stream = Instance(DummySocket, ()) # type:ignore[arg-type]
54+
shell_stream = Instance(DummySocket, ()) # type:ignore[assignment]
5555

5656
@default("iopub_thread")
5757
def _default_iopub_thread(self):
@@ -65,7 +65,7 @@ def _default_iopub_thread(self):
6565
def _default_iopub_socket(self):
6666
return self.iopub_thread.background_socket
6767

68-
stdin_socket = Instance(DummySocket, ()) # type:ignore[assignment]
68+
stdin_socket = Instance(DummySocket, ())
6969

7070
def __init__(self, **traits):
7171
"""Initialize the kernel."""
@@ -85,7 +85,7 @@ def start(self):
8585
if self.shell:
8686
self.shell.exit_now = False
8787

88-
def _abort_queues(self):
88+
def _abort_queues(self, subshell_id: str | None = ...):
8989
"""The in-process kernel doesn't abort requests."""
9090

9191
def _input_request(self, prompt, ident, parent, password=False):

ipykernel/ipkernel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def dispatch_debugpy(self, msg):
231231
self.debugger.tcp_client.receive_dap_frame(frame)
232232

233233
@property
234-
def banner(self):
234+
def banner(self): # type:ignore[override]
235235
if self.shell:
236236
return self.shell.banner
237237
return None
@@ -455,7 +455,7 @@ async def run_cell(*args, **kwargs):
455455
if threading.current_thread() == threading.main_thread()
456456
else self._dummy_context_manager
457457
)
458-
with cm(coro_future): # type:ignore[operator]
458+
with cm(coro_future):
459459
res = None
460460
try:
461461
res = await coro_future

ipykernel/kernelapp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
118118
"""The IPYKernel application class."""
119119

120120
name = "ipython-kernel"
121-
aliases = Dict(kernel_aliases) # type:ignore[assignment]
122-
flags = Dict(kernel_flags) # type:ignore[assignment]
123-
classes = [IPythonKernel, ZMQInteractiveShell, ProfileDir, Session]
121+
aliases = Dict(kernel_aliases)
122+
flags = Dict(kernel_flags)
123+
classes = [IPythonKernel, ZMQInteractiveShell, ProfileDir, Session] # type:ignore[assignment]
124124
# the kernel class, as an importstring
125125
kernel_class = Type(
126126
"ipykernel.ipkernel.IPythonKernel",
@@ -261,7 +261,7 @@ def _bind_socket(self, s, port):
261261
raise
262262
return None
263263

264-
def write_connection_file(self):
264+
def write_connection_file(self, **kwargs: Any) -> None:
265265
"""write connection info to JSON file"""
266266
cf = self.abs_connection_file
267267
connection_info = dict(

ipykernel/zmqshell.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import sys
1919
import threading
20+
import typing
2021
import warnings
2122
from pathlib import Path
2223

@@ -78,12 +79,16 @@ def _hooks(self):
7879
self._thread_local.hooks = []
7980
return self._thread_local.hooks
8081

81-
def publish(
82+
# Feb: 2025 IPython has a deprecated, `source` parameter, marked for removal that
83+
# triggers typing errors.
84+
def publish( # type:ignore[override]
8285
self,
8386
data,
8487
metadata=None,
88+
*,
8589
transient=None,
8690
update=False,
91+
**kwargs,
8792
):
8893
"""Publish a display-data message
8994
@@ -125,7 +130,7 @@ def publish(
125130
for hook in self._hooks:
126131
msg = hook(msg)
127132
if msg is None:
128-
return # type:ignore[unreachable]
133+
return
129134

130135
self.session.send(
131136
self.pub_socket,
@@ -153,7 +158,7 @@ def clear_output(self, wait=False):
153158
for hook in self._hooks:
154159
msg = hook(msg)
155160
if msg is None:
156-
return # type:ignore[unreachable]
161+
return
157162

158163
self.session.send(
159164
self.pub_socket,
@@ -482,7 +487,7 @@ def __init__(self, *args, **kwargs):
482487

483488
displayhook_class = Type(ZMQShellDisplayHook)
484489
display_pub_class = Type(ZMQDisplayPublisher)
485-
data_pub_class = Any() # type:ignore[assignment]
490+
data_pub_class = Any()
486491
kernel = Any()
487492
parent_header = Any()
488493

@@ -520,7 +525,7 @@ def _update_exit_now(self, change):
520525

521526
# Over ZeroMQ, GUI control isn't done with PyOS_InputHook as there is no
522527
# interactive input being read; we provide event loop support in ipkernel
523-
def enable_gui(self, gui):
528+
def enable_gui(self, gui: typing.Any = None) -> None:
524529
"""Enable a given guil."""
525530
from .eventloops import enable_gui as real_enable_gui
526531

@@ -590,7 +595,7 @@ def data_pub(self):
590595
stacklevel=2,
591596
)
592597

593-
self._data_pub = self.data_pub_class(parent=self) # type:ignore[has-type]
598+
self._data_pub = self.data_pub_class(parent=self)
594599
self._data_pub.session = self.display_pub.session # type:ignore[attr-defined]
595600
self._data_pub.pub_socket = self.display_pub.pub_socket # type:ignore[attr-defined]
596601
return self._data_pub
@@ -660,14 +665,10 @@ def set_parent(self, parent):
660665
self.display_pub.set_parent(parent) # type:ignore[attr-defined]
661666
if hasattr(self, "_data_pub"):
662667
self.data_pub.set_parent(parent)
663-
try:
664-
sys.stdout.set_parent(parent) # type:ignore[attr-defined]
665-
except AttributeError:
666-
pass
667-
try:
668-
sys.stderr.set_parent(parent) # type:ignore[attr-defined]
669-
except AttributeError:
670-
pass
668+
if hasattr(sys.stdout, "set_parent"):
669+
sys.stdout.set_parent(parent)
670+
if hasattr(sys.stderr, "set_parent"):
671+
sys.stderr.set_parent(parent)
671672

672673
def get_parent(self):
673674
"""Get the parent header."""

0 commit comments

Comments
 (0)