Skip to content

Commit 944642c

Browse files
committed
update mypy errors
1 parent 72207a8 commit 944642c

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ repos:
4444
hooks:
4545
- id: mypy
4646
files: ipykernel
47-
stages: [manual]
4847
args: ["--install-types", "--non-interactive"]
4948
additional_dependencies:
5049
[

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: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# Imports
1212
# -----------------------------------------------------------------------------
1313

14+
from typing import Any
15+
1416
from jupyter_client.client import KernelClient
1517
from jupyter_client.clientabc import KernelClientABC
1618

@@ -54,9 +56,9 @@ def _default_blocking_class(self):
5456

5557
return BlockingInProcessKernelClient
5658

57-
def get_connection_info(self):
59+
def get_connection_info(self, session: bool = False):
5860
"""Get the connection info for the client."""
59-
d = super().get_connection_info()
61+
d = super().get_connection_info(session=session)
6062
d["kernel"] = self.kernel # type:ignore[assignment]
6163
return d
6264

@@ -99,9 +101,18 @@ def hb_channel(self):
99101
# Methods for sending specific messages
100102
# -------------------------------------
101103

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

119132
async def complete(self, code, cursor_pos=None):
120133
"""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/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: 2025IPython 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)