Skip to content

Commit 686d5c9

Browse files
committed
Run Mypy by default.
Otherwise the types annotations are less usefull, even with ruff. Ignore/fix types errors.
1 parent 3089438 commit 686d5c9

File tree

7 files changed

+26
-11
lines changed

7 files changed

+26
-11
lines changed

.pre-commit-config.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ 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.11.0"
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

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def call_handlers(self, msg):
6868
_raw_input = self.client.kernel._sys_raw_input
6969
prompt = msg["content"]["prompt"]
7070
print(prompt, end="", file=sys.__stdout__)
71+
assert sys.__stdout__ is not None
7172
sys.__stdout__.flush()
7273
self.client.input(_raw_input())
7374

ipykernel/inprocess/client.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _default_blocking_class(self):
5555

5656
return BlockingInProcessKernelClient
5757

58-
def get_connection_info(self):
58+
def get_connection_info(self): # type: ignore[override]
5959
"""Get the connection info for the client."""
6060
d = super().get_connection_info()
6161
d["kernel"] = self.kernel # type:ignore[assignment]
@@ -100,8 +100,13 @@ def hb_channel(self):
100100
# Methods for sending specific messages
101101
# -------------------------------------
102102

103-
async def execute(
104-
self, code, silent=False, store_history=True, user_expressions=None, allow_stdin=None
103+
async def execute( # type: ignore[override]
104+
self,
105+
code,
106+
silent=False,
107+
store_history=True,
108+
user_expressions=None,
109+
allow_stdin=None,
105110
):
106111
"""Execute code on the client."""
107112
if allow_stdin is None:

ipykernel/inprocess/session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Session(_Session):
5-
async def recv(self, socket, copy=True):
5+
async def recv(self, socket, copy=True): # type: ignore [override]
66
return await socket.recv_multipart()
77

88
def send(

ipykernel/kernelapp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -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): # type: ignore[override]
265265
"""write connection info to JSON file"""
266266
cf = self.abs_connection_file
267267
connection_info = dict(

ipykernel/kernelbase.py

+8
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ def _parent_header(self):
233233
]
234234

235235
_eventloop_set: Event = Event()
236+
control_handlers: Dict[
237+
str,
238+
t.Callable[[zmq.asyncio.Socket, list[bytes], str], t.Awaitable[t.Any]]
239+
|
240+
# I think this one should be deprecated, and we should check the handlers are
241+
# coroutine functions.
242+
t.Callable[[zmq.asyncio.Socket, list[bytes], str], t.Any],
243+
]
236244

237245
def __init__(self, **kwargs):
238246
"""Initialize the kernel."""

ipykernel/zmqshell.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _hooks(self):
7878
self._thread_local.hooks = []
7979
return self._thread_local.hooks
8080

81-
def publish(
81+
def publish( # type:ignore[override]
8282
self,
8383
data,
8484
metadata=None,
@@ -516,7 +516,7 @@ def _update_exit_now(self, change):
516516

517517
# Over ZeroMQ, GUI control isn't done with PyOS_InputHook as there is no
518518
# interactive input being read; we provide event loop support in ipkernel
519-
def enable_gui(self, gui):
519+
def enable_gui(self, gui): # type:ignore[override]
520520
"""Enable a given guil."""
521521
from .eventloops import enable_gui as real_enable_gui
522522

@@ -635,11 +635,13 @@ def set_parent(self, parent):
635635
if hasattr(self, "_data_pub"):
636636
self.data_pub.set_parent(parent)
637637
try:
638-
sys.stdout.set_parent(parent) # type:ignore[attr-defined]
638+
stdout = sys.stdout
639+
stdout.set_parent(parent) # type:ignore[union-attr]
639640
except AttributeError:
640641
pass
641642
try:
642-
sys.stderr.set_parent(parent) # type:ignore[attr-defined]
643+
stderr = sys.stderr
644+
stderr.set_parent(parent) # type:ignore[union-attr]
643645
except AttributeError:
644646
pass
645647

0 commit comments

Comments
 (0)