Skip to content

Commit

Permalink
Run Mypy by default.
Browse files Browse the repository at this point in the history
Otherwise the types annotations are less usefull, even with ruff.

Ignore/fix types errors.
  • Loading branch information
Carreau committed Oct 15, 2024
1 parent 314cc49 commit 258fdf3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ repos:
types_or: [yaml, html, json]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0"
rev: "v1.11.0"
hooks:
- id: mypy
files: ipykernel
stages: [manual]
args: ["--install-types", "--non-interactive"]
additional_dependencies:
[
Expand Down
1 change: 1 addition & 0 deletions ipykernel/inprocess/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def call_handlers(self, msg):
_raw_input = self.client.kernel._sys_raw_input
prompt = msg["content"]["prompt"]
print(prompt, end="", file=sys.__stdout__)
assert sys.__stdout__ is not None
sys.__stdout__.flush()
self.client.input(_raw_input())

Expand Down
11 changes: 8 additions & 3 deletions ipykernel/inprocess/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _default_blocking_class(self):

return BlockingInProcessKernelClient

def get_connection_info(self):
def get_connection_info(self): # type: ignore[override]
"""Get the connection info for the client."""
d = super().get_connection_info()
d["kernel"] = self.kernel # type:ignore[assignment]
Expand Down Expand Up @@ -100,8 +100,13 @@ def hb_channel(self):
# Methods for sending specific messages
# -------------------------------------

async def execute(
self, code, silent=False, store_history=True, user_expressions=None, allow_stdin=None
async def execute( # type: ignore[override]
self,
code,
silent=False,
store_history=True,
user_expressions=None,
allow_stdin=None,
):
"""Execute code on the client."""
if allow_stdin is None:
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/inprocess/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


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

def send(
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _bind_socket(self, s, port):
raise
return None

def write_connection_file(self):
def write_connection_file(self): # type: ignore[override]
"""write connection info to JSON file"""
cf = self.abs_connection_file
connection_info = dict(
Expand Down
8 changes: 8 additions & 0 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ def _parent_header(self):
]

_eventloop_set: Event = Event()
control_handlers: Dict[
str,
t.Callable[[zmq.asyncio.Socket, list[bytes], str], t.Awaitable[t.Any]]
|
# I think this one should be deprecated, and we should check the handlers are
# coroutine functions.
t.Callable[[zmq.asyncio.Socket, list[bytes], str], t.Any],
]

def __init__(self, **kwargs):
"""Initialize the kernel."""
Expand Down
10 changes: 6 additions & 4 deletions ipykernel/zmqshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _hooks(self):
self._thread_local.hooks = []
return self._thread_local.hooks

def publish(
def publish( # type:ignore[override]
self,
data,
metadata=None,
Expand Down Expand Up @@ -516,7 +516,7 @@ def _update_exit_now(self, change):

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

Expand Down Expand Up @@ -635,11 +635,13 @@ def set_parent(self, parent):
if hasattr(self, "_data_pub"):
self.data_pub.set_parent(parent)
try:
sys.stdout.set_parent(parent) # type:ignore[attr-defined]
stdout = sys.stdout
stdout.set_parent(parent) # type:ignore[union-attr]
except AttributeError:
pass
try:
sys.stderr.set_parent(parent) # type:ignore[attr-defined]
stderr = sys.stderr
stderr.set_parent(parent) # type:ignore[union-attr]
except AttributeError:
pass

Expand Down

0 comments on commit 258fdf3

Please sign in to comment.