Skip to content

Commit 1f70018

Browse files
committed
strict all the way
1 parent dadb3da commit 1f70018

12 files changed

+43
-33
lines changed

ipykernel/comm/comm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import comm.base_comm
1111
import traitlets.config
12-
from traitlets import Bool, Bytes, Instance, Unicode, default
12+
from traitlets import Bool, Instance, Unicode, default
1313

1414
from ipykernel.jsonutil import json_clean
1515
from ipykernel.kernelbase import Kernel
@@ -50,18 +50,18 @@ class Comm(BaseComm, traitlets.config.LoggingConfigurable):
5050
"""Class for communicating between a Frontend and a Kernel"""
5151

5252
kernel = Instance("ipykernel.kernelbase.Kernel", allow_none=True) # type:ignore[assignment]
53-
comm_id = Unicode()
54-
primary = Bool(True, help="Am I the primary or secondary Comm?")
53+
comm_id = Unicode() # type: ignore[assignment]
54+
primary = Bool(True, help="Am I the primary or secondary Comm?") # type: ignore[assignment]
5555

56-
target_name = Unicode("comm")
57-
target_module = Unicode(
56+
target_name = Unicode("comm") # type: ignore[assignment]
57+
target_module = Unicode( # type: ignore[assignment]
5858
None,
5959
allow_none=True,
6060
help="""requirejs module from
6161
which to load comm target.""",
6262
)
6363

64-
topic = Bytes()
64+
topic: bytes
6565

6666
@default("kernel")
6767
def _default_kernel(self):

ipykernel/comm/manager.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import comm.base_comm
99
import traitlets
1010
import traitlets.config
11+
from typing import Dict, Any
1112

1213
from .comm import Comm
1314

@@ -18,8 +19,8 @@ class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurab
1819
"""A comm manager."""
1920

2021
kernel = traitlets.Instance("ipykernel.kernelbase.Kernel")
21-
comms = traitlets.Dict()
22-
targets = traitlets.Dict()
22+
comms: Dict[Any, Any]
23+
targets: Dict[str, Any]
2324

2425
def __init__(self, **kwargs):
2526
"""Initialize the manager."""
@@ -33,7 +34,7 @@ def comm_open(self, stream, ident, msg):
3334
# but we should let the base class create the comm with comm.create_comm in a major release
3435
content = msg["content"]
3536
comm_id = content["comm_id"]
36-
target_name = content["target_name"]
37+
target_name: str = content["target_name"]
3738
f = self.targets.get(target_name, None)
3839
comm = Comm(
3940
comm_id=comm_id,

ipykernel/debugger.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
try:
2323
# This import is required to have the next ones working...
24-
from debugpy.server import api # noqa: F401
24+
from debugpy.server import api # type: ignore[import-untyped]# noqa: F401
2525

2626
from _pydevd_bundle import ( # type:ignore[import-not-found]
2727
pydevd_frame_utils,
@@ -119,9 +119,10 @@ def __init__(self, event_callback, log):
119119
self.tcp_buffer = ""
120120
self._reset_tcp_pos()
121121
self.event_callback = event_callback
122-
self.message_send_stream, self.message_receive_stream = create_memory_object_stream[dict](
123-
max_buffer_size=inf
124-
)
122+
(
123+
self.message_send_stream,
124+
self.message_receive_stream,
125+
) = create_memory_object_stream[dict[t.Any, t.Any]](max_buffer_size=inf)
125126
self.log = log
126127

127128
def _reset_tcp_pos(self):
@@ -344,9 +345,10 @@ def __init__(
344345
self.is_started = False
345346
self.event_callback = event_callback
346347
self.just_my_code = just_my_code
347-
self.stopped_send_stream, self.stopped_receive_stream = create_memory_object_stream[dict](
348-
max_buffer_size=inf
349-
)
348+
(
349+
self.stopped_send_stream,
350+
self.stopped_receive_stream,
351+
) = create_memory_object_stream[dict[t.Any, t.Any]](max_buffer_size=inf)
350352

351353
self.started_debug_handlers = {}
352354
for msg_type in Debugger.started_debug_msg_types:

ipykernel/eventloops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def _schedule_exit(delay):
279279
else:
280280
import asyncio
281281

282-
import nest_asyncio
282+
import nest_asyncio # type: ignore [import-untyped]
283283

284284
nest_asyncio.apply()
285285

ipykernel/inprocess/ipkernel.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ async def execute_request(self, stream, ident, parent):
8282
with self._redirected_io():
8383
await super().execute_request(stream, ident, parent)
8484

85-
async def start(self, *, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None:
85+
async def start(
86+
self, *, task_status: TaskStatus[None] = TASK_STATUS_IGNORED
87+
) -> None:
8688
"""Override registration of dispatchers for streams."""
8789
if self.shell:
8890
self.shell.exit_now = False

ipykernel/inprocess/manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _default_session(self):
4646
# --------------------------------------------------------------------------
4747

4848
async def start_kernel( # type: ignore[explicit-override, override]
49-
self, *, task_status: TaskStatus = TASK_STATUS_IGNORED, **kwds: Any
49+
self, *, task_status: TaskStatus[None] = TASK_STATUS_IGNORED, **kwds: Any
5050
) -> None:
5151
"""Start the kernel."""
5252
from ipykernel.inprocess.ipkernel import InProcessKernel
@@ -65,7 +65,7 @@ async def restart_kernel( # type: ignore[explicit-override, override]
6565
now: bool = False,
6666
newports: bool = False,
6767
*,
68-
task_status: TaskStatus = TASK_STATUS_IGNORED,
68+
task_status: TaskStatus[None] = TASK_STATUS_IGNORED,
6969
**kw: Any,
7070
) -> None:
7171
"""Restart the kernel."""

ipykernel/inprocess/socket.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import zmq.asyncio
1010
from anyio import create_memory_object_stream
1111
from traitlets import HasTraits, Instance
12+
from typing import Any
1213

1314
# -----------------------------------------------------------------------------
1415
# Dummy socket class
@@ -32,12 +33,12 @@ def __init__(self, is_shell, *args, **kwargs):
3233
self.is_shell = is_shell
3334
self.on_recv = None
3435
if is_shell:
35-
self.in_send_stream, self.in_receive_stream = create_memory_object_stream[dict](
36-
max_buffer_size=inf
37-
)
38-
self.out_send_stream, self.out_receive_stream = create_memory_object_stream[dict](
39-
max_buffer_size=inf
40-
)
36+
self.in_send_stream, self.in_receive_stream = create_memory_object_stream[
37+
dict[Any, Any]
38+
](max_buffer_size=inf)
39+
self.out_send_stream, self.out_receive_stream = create_memory_object_stream[
40+
dict[Any, Any]
41+
](max_buffer_size=inf)
4142

4243
def put(self, msg):
4344
self.in_send_stream.send_nowait(msg)

ipykernel/ipkernel.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ async def poll_stopped_queue(self):
246246
while True:
247247
await self.debugger.handle_stopped_event()
248248

249-
async def start(self, *, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None:
249+
async def start(
250+
self, *, task_status: TaskStatus[None] = TASK_STATUS_IGNORED
251+
) -> None:
250252
"""Start the kernel."""
251253
if self.shell:
252254
self.shell.exit_now = False

ipykernel/kernelbase.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,9 @@ def pre_handler_hook(self):
539539
def post_handler_hook(self):
540540
"""Hook to execute after calling message handler"""
541541

542-
async def start(self, *, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None:
542+
async def start(
543+
self, *, task_status: TaskStatus[None] = TASK_STATUS_IGNORED
544+
) -> None:
543545
"""Process messages on shell and control channels"""
544546
async with create_task_group() as tg:
545547
self.control_stop = threading.Event()

ipykernel/pickleutil.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def use_dill():
7676
adds support for object methods and closures to serialization.
7777
"""
7878
# import dill causes most of the magic
79-
import dill
79+
import dill # type: ignore[import-untyped]
8080

8181
# dill doesn't work with cPickle,
8282
# tell the two relevant modules to use plain pickle
@@ -100,7 +100,7 @@ def use_cloudpickle():
100100
101101
adds support for object methods and closures to serialization.
102102
"""
103-
import cloudpickle
103+
import cloudpickle # type: ignore[import-untyped]
104104

105105
global pickle # noqa: PLW0603
106106
pickle = cloudpickle

ipykernel/trio_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def trio_main():
5050
async with trio.open_nursery() as nursery:
5151
# TODO This hack prevents the nursery from cancelling all child
5252
# tasks when an uncaught exception occurs, but it's ugly.
53-
nursery._add_exc = log_nursery_exc
53+
nursery._add_exc = log_nursery_exc # type: ignore [method-assign]
5454
builtins.GLOBAL_NURSERY = nursery # type:ignore[attr-defined]
5555
await trio.sleep_forever()
5656

ipykernel/zmqshell.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,12 @@ def set_parent(self, parent):
636636
self.data_pub.set_parent(parent)
637637
try:
638638
stdout = sys.stdout
639-
stdout.set_parent(parent)
639+
stdout.set_parent(parent) # type: ignore[attr-defined]
640640
except AttributeError:
641641
pass
642642
try:
643643
stderr = sys.stderr
644-
stderr.set_parent(parent)
644+
stderr.set_parent(parent) # type: ignore[attr-defined]
645645
except AttributeError:
646646
pass
647647

0 commit comments

Comments
 (0)