Skip to content

Commit f9cfd11

Browse files
Carreaukrassowski
andauthored
Bump mypy (#1333)
Co-authored-by: Michał Krassowski <[email protected]>
1 parent f0d0d91 commit f9cfd11

File tree

6 files changed

+44
-20
lines changed

6 files changed

+44
-20
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ 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.15.0"
4444
hooks:
4545
- id: mypy
4646
files: ipykernel
47-
stages: [manual]
4847
args: ["--install-types", "--non-interactive"]
4948
additional_dependencies:
5049
[
5150
"traitlets>=5.13",
5251
"ipython>=8.16.1",
5352
"jupyter_client>=8.5",
5453
"appnope",
54+
"types-psutil",
5555
]
5656

5757
- repo: https://github.com/adamchainz/blacken-docs

ipykernel/inprocess/blocking.py

Lines changed: 1 addition & 0 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

ipykernel/inprocess/client.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
# Imports
1212
# -----------------------------------------------------------------------------
1313

14+
15+
from typing import Any
16+
1417
from jupyter_client.client import KernelClient
1518
from jupyter_client.clientabc import KernelClientABC
1619

@@ -54,9 +57,9 @@ def _default_blocking_class(self):
5457

5558
return BlockingInProcessKernelClient
5659

57-
def get_connection_info(self):
60+
def get_connection_info(self, session: bool = False):
5861
"""Get the connection info for the client."""
59-
d = super().get_connection_info()
62+
d = super().get_connection_info(session=session)
6063
d["kernel"] = self.kernel # type:ignore[assignment]
6164
return d
6265

@@ -99,9 +102,18 @@ def hb_channel(self):
99102
# Methods for sending specific messages
100103
# -------------------------------------
101104

102-
async def execute(
103-
self, code, silent=False, store_history=True, user_expressions=None, allow_stdin=None
104-
):
105+
# Feb 2025: superclass in jupyter-Client is sync,
106+
# it should likely be made all consistent and push
107+
# jupyter_client async as well
108+
async def execute( # type:ignore [override]
109+
self,
110+
code: str,
111+
silent: bool = False,
112+
store_history: bool = True,
113+
user_expressions: dict[str, Any] | None = None,
114+
allow_stdin: bool | None = None,
115+
stop_on_error: bool = True,
116+
) -> str:
105117
"""Execute code on the client."""
106118
if allow_stdin is None:
107119
allow_stdin = self.allow_stdin
@@ -114,7 +126,9 @@ async def execute(
114126
)
115127
msg = self.session.msg("execute_request", content)
116128
await self._dispatch_to_kernel(msg)
117-
return msg["header"]["msg_id"]
129+
res = msg["header"]["msg_id"]
130+
assert isinstance(res, str)
131+
return res
118132

119133
async def complete(self, code, cursor_pos=None):
120134
"""Get code completion."""

ipykernel/inprocess/session.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
from typing import Any
2+
13
from jupyter_client.session import Session as _Session
24

35

46
class Session(_Session):
5-
async def recv(self, socket, copy=True):
7+
# superclass is not async.
8+
async def recv( # type: ignore[override]
9+
self, socket, mode: int = 0, content: bool = True, copy=True
10+
) -> Any:
11+
"""
12+
mode, content, copy have no effect, but are present for superclass compatibility
13+
14+
"""
615
return await socket.recv_multipart()
716

817
def send(

ipykernel/kernelapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def init_io(self):
514514
isinstance(handler, StreamHandler)
515515
and (buffer := getattr(handler.stream, "buffer", None))
516516
and (fileno := getattr(buffer, "fileno", None))
517-
and fileno() == sys.stderr._original_stdstream_fd # type:ignore[attr-defined]
517+
and fileno() == sys.stderr._original_stdstream_fd
518518
):
519519
self.log.debug("Seeing logger to stderr, rerouting to raw filedescriptor.")
520520
io_wrapper = TextIOWrapper(

ipykernel/zmqshell.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ def _hooks(self):
7878
self._thread_local.hooks = []
7979
return self._thread_local.hooks
8080

81-
def publish(
81+
# Feb: 2025 IPython has a deprecated, `source` parameter, marked for removal that
82+
# triggers typing errors.
83+
def publish( # type: ignore [override]
8284
self,
8385
data,
8486
metadata=None,
87+
*,
8588
transient=None,
8689
update=False,
90+
**kwargs,
8791
):
8892
"""Publish a display-data message
8993
@@ -508,7 +512,7 @@ def _update_exit_now(self, change):
508512

509513
# Over ZeroMQ, GUI control isn't done with PyOS_InputHook as there is no
510514
# interactive input being read; we provide event loop support in ipkernel
511-
def enable_gui(self, gui):
515+
def enable_gui(self, gui=None):
512516
"""Enable a given guil."""
513517
from .eventloops import enable_gui as real_enable_gui
514518

@@ -654,14 +658,10 @@ def set_parent(self, parent):
654658
self.display_pub.set_parent(parent) # type:ignore[attr-defined]
655659
if hasattr(self, "_data_pub"):
656660
self.data_pub.set_parent(parent)
657-
try:
658-
sys.stdout.set_parent(parent) # type:ignore[attr-defined]
659-
except AttributeError:
660-
pass
661-
try:
662-
sys.stderr.set_parent(parent) # type:ignore[attr-defined]
663-
except AttributeError:
664-
pass
661+
if hasattr(sys.stdout, "set_parent"):
662+
sys.stdout.set_parent(parent)
663+
if hasattr(sys.stderr, "set_parent"):
664+
sys.stderr.set_parent(parent)
665665

666666
def get_parent(self):
667667
"""Get the parent header."""

0 commit comments

Comments
 (0)