Skip to content

Commit 22b2d21

Browse files
authored
Clean up typing config (#1163)
1 parent 3c4b5bf commit 22b2d21

File tree

13 files changed

+41
-47
lines changed

13 files changed

+41
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- name: Run Linters
8585
run: |
8686
hatch run typing:test
87-
hatch run lint:style
87+
hatch run lint:build
8888
pipx run interrogate -vv .
8989
pipx run doc8 --max-line-length=200
9090

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ repos:
3939
- id: prettier
4040
types_or: [yaml, html, json]
4141

42+
- repo: https://github.com/pre-commit/mirrors-mypy
43+
rev: "v1.6.1"
44+
hooks:
45+
- id: mypy
46+
files: ipykernel
47+
stages: [manual]
48+
args: ["--install-types", "--non-interactive"]
49+
additional_dependencies:
50+
[
51+
"traitlets>=5.13",
52+
"ipython>=8.16.1",
53+
"jupyter_client>=8.5",
54+
"appnope",
55+
]
56+
4257
- repo: https://github.com/adamchainz/blacken-docs
4358
rev: "1.16.0"
4459
hooks:

ipykernel/comm/comm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
# this is the class that will be created if we do comm.create_comm
19-
class BaseComm(comm.base_comm.BaseComm):
19+
class BaseComm(comm.base_comm.BaseComm): # type:ignore[misc]
2020
"""The base class for comms."""
2121

2222
kernel: Optional["Kernel"] = None

ipykernel/comm/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
logger = logging.getLogger("ipykernel.comm")
1515

1616

17-
class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurable):
17+
class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurable): # type:ignore[misc]
1818
"""A comm manager."""
1919

2020
kernel = traitlets.Instance("ipykernel.kernelbase.Kernel")

ipykernel/connect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def get_connection_info(
8888
return info_str
8989

9090

91-
def connect_qtconsole(connection_file: str | None = None, argv: list[str] | None = None) -> Popen:
91+
def connect_qtconsole(
92+
connection_file: str | None = None, argv: list[str] | None = None
93+
) -> Popen[Any]:
9294
"""Connect a qtconsole to the current kernel.
9395
9496
This is useful for connecting a second qtconsole to a kernel, or to a

ipykernel/eventloops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def wake():
168168

169169
# We have to put the wx.Timer in a wx.Frame for it to fire properly.
170170
# We make the Frame hidden when we create it in the main app below.
171-
class TimerFrame(wx.Frame):
171+
class TimerFrame(wx.Frame): # type:ignore[misc]
172172
def __init__(self, func):
173173
wx.Frame.__init__(self, None, -1)
174174
self.timer = wx.Timer(self)
@@ -182,7 +182,7 @@ def on_timer(self, event):
182182

183183
# We need a custom wx.App to create our Frame subclass that has the
184184
# wx.Timer to defer back to the tornado event loop.
185-
class IPWxApp(wx.App):
185+
class IPWxApp(wx.App): # type:ignore[misc]
186186
def OnInit(self):
187187
self.frame = TimerFrame(wake)
188188
self.frame.Show(False)

ipykernel/iostream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __init__(self, socket, pipe=False):
6969
self._event_pipes: Dict[threading.Thread, Any] = {}
7070
self._event_pipe_gc_lock: threading.Lock = threading.Lock()
7171
self._event_pipe_gc_seconds: float = 10
72-
self._event_pipe_gc_task: Optional[asyncio.Task] = None
72+
self._event_pipe_gc_task: Optional[asyncio.Task[Any]] = None
7373
self._setup_event_pipe()
7474
self.thread = threading.Thread(target=self._thread_main, name="IOPub")
7575
self.thread.daemon = True

ipykernel/ipkernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def __init__(self, **kwargs):
147147

148148
if _use_appnope() and self._darwin_app_nap:
149149
# Disable app-nap as the kernel is not a gui but can have guis
150-
import appnope
150+
import appnope # type:ignore[import-untyped]
151151

152152
appnope.nope()
153153

ipykernel/kernelapp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Copyright (c) IPython Development Team.
44
# Distributed under the terms of the Modified BSD License.
5+
from __future__ import annotations
56

67
import atexit
78
import errno
@@ -10,10 +11,10 @@
1011
import signal
1112
import sys
1213
import traceback
14+
import typing as t
1315
from functools import partial
1416
from io import FileIO, TextIOWrapper
1517
from logging import StreamHandler
16-
from typing import Optional
1718

1819
import zmq
1920
from IPython.core.application import ( # type:ignore[attr-defined]
@@ -132,7 +133,7 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
132133
poller = Any() # don't restrict this even though current pollers are all Threads
133134
heartbeat = Instance(Heartbeat, allow_none=True)
134135

135-
context: Optional[zmq.Context] = Any() # type:ignore[assignment]
136+
context: zmq.Context[t.Any] | None = Any() # type:ignore[assignment]
136137
shell_socket = Any()
137138
control_socket = Any()
138139
debugpy_socket = Any()

ipykernel/kernelbase.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@ async def usage_request(self, stream, ident, parent):
10441044
# Ensure 1) self.processes is updated to only current subprocesses
10451045
# and 2) we reuse processes when possible (needed for accurate CPU)
10461046
self.processes = {
1047-
process.pid: self.processes.get(process.pid, process) for process in all_processes
1047+
process.pid: self.processes.get(process.pid, process) # type:ignore[misc,call-overload]
1048+
for process in all_processes
10481049
}
10491050
reply_content["kernel_cpu"] = sum(
10501051
[
@@ -1062,7 +1063,7 @@ async def usage_request(self, stream, ident, parent):
10621063
cpu_percent = psutil.cpu_percent()
10631064
# https://psutil.readthedocs.io/en/latest/index.html?highlight=cpu#psutil.cpu_percent
10641065
# The first time cpu_percent is called it will return a meaningless 0.0 value which you are supposed to ignore.
1065-
if cpu_percent is not None and cpu_percent != 0.0:
1066+
if cpu_percent is not None and cpu_percent != 0.0: # type:ignore[redundant-expr]
10661067
reply_content["host_cpu_percent"] = cpu_percent
10671068
reply_content["cpu_count"] = psutil.cpu_count(logical=True)
10681069
reply_content["host_virtual_memory"] = dict(psutil.virtual_memory()._asdict())

0 commit comments

Comments
 (0)