Skip to content

Commit d02f437

Browse files
authored
Merge pull request #933 from blink1073/fix-types
2 parents 97847d7 + dbdd3a8 commit d02f437

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ repos:
4747
- id: mypy
4848
exclude: "ipykernel.*tests"
4949
args: ["--config-file", "pyproject.toml"]
50-
additional_dependencies: [tornado, jupyter_client, pytest]
50+
additional_dependencies:
51+
[tornado, jupyter_client, pytest, traitlets, jupyter_core]
5152
stages: [manual]
5253

5354
- repo: https://github.com/pycqa/flake8

ipykernel/inprocess/ipkernel.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class InProcessKernel(IPythonKernel):
4848

4949
shell_class = Type(allow_none=True)
5050
_underlying_iopub_socket = Instance(DummySocket, ())
51-
iopub_thread = Instance(IOPubThread)
51+
iopub_thread: IOPubThread = Instance(IOPubThread) # type:ignore[assignment]
5252

5353
shell_stream = Instance(DummySocket, ())
5454

@@ -58,13 +58,13 @@ def _default_iopub_thread(self):
5858
thread.start()
5959
return thread
6060

61-
iopub_socket = Instance(BackgroundSocket)
61+
iopub_socket: BackgroundSocket = Instance(BackgroundSocket) # type:ignore[assignment]
6262

6363
@default("iopub_socket")
6464
def _default_iopub_socket(self):
6565
return self.iopub_thread.background_socket
6666

67-
stdin_socket = Instance(DummySocket, ())
67+
stdin_socket = Instance(DummySocket, ()) # type:ignore[assignment]
6868

6969
def __init__(self, **traits):
7070
super().__init__(**traits)
@@ -127,6 +127,7 @@ def _redirected_io(self):
127127

128128
def _io_dispatch(self, change):
129129
"""Called when a message is sent to the IO socket."""
130+
assert self.iopub_socket.io_thread is not None
130131
ident, msg = self.session.recv(self.iopub_socket.io_thread.socket, copy=False)
131132
for frontend in self.frontends:
132133
frontend.iopub_channel.call_handlers(msg)
@@ -163,7 +164,9 @@ def _default_stderr(self):
163164

164165
class InProcessInteractiveShell(ZMQInteractiveShell):
165166

166-
kernel = Instance("ipykernel.inprocess.ipkernel.InProcessKernel", allow_none=True)
167+
kernel: InProcessKernel = Instance(
168+
"ipykernel.inprocess.ipkernel.InProcessKernel", allow_none=True
169+
) # type:ignore[assignment]
167170

168171
# -------------------------------------------------------------------------
169172
# InteractiveShell interface

ipykernel/kernelapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from jupyter_client.session import Session, session_aliases, session_flags
2929
from jupyter_core.paths import jupyter_runtime_dir
3030
from tornado import ioloop
31-
from traitlets import (
31+
from traitlets.traitlets import (
3232
Any,
3333
Bool,
3434
Dict,

ipykernel/kernelbase.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
from jupyter_client.session import Session
3939
from tornado import ioloop
4040
from tornado.queues import Queue, QueueEmpty
41-
from traitlets import (
41+
from traitlets.config.configurable import SingletonConfigurable
42+
from traitlets.traitlets import (
4243
Any,
4344
Bool,
4445
Dict,
@@ -51,7 +52,6 @@
5152
default,
5253
observe,
5354
)
54-
from traitlets.config.configurable import SingletonConfigurable
5555
from zmq.eventloop.zmqstream import ZMQStream
5656

5757
from ipykernel.jsonutil import json_clean
@@ -95,6 +95,10 @@ def _update_eventloop(self, change):
9595
"""
9696
)
9797

98+
implementation: str
99+
implementation_version: str
100+
banner: str
101+
98102
@default("shell_streams")
99103
def _shell_streams_default(self):
100104
warnings.warn(
@@ -131,7 +135,7 @@ def _shell_streams_changed(self, change):
131135
iopub_socket = Any()
132136
iopub_thread = Any()
133137
stdin_socket = Any()
134-
log = Instance(logging.Logger, allow_none=True)
138+
log: logging.Logger = Instance(logging.Logger, allow_none=True) # type:ignore[assignment]
135139

136140
# identities:
137141
int_id = Integer(-1)
@@ -263,7 +267,7 @@ def __init__(self, **kwargs):
263267
for msg_type in self.control_msg_types:
264268
self.control_handlers[msg_type] = getattr(self, msg_type)
265269

266-
self.control_queue: Queue[Any] = Queue()
270+
self.control_queue: Queue[t.Any] = Queue()
267271

268272
def dispatch_control(self, msg):
269273
self.control_queue.put_nowait(msg)
@@ -531,7 +535,7 @@ def schedule_dispatch(self, dispatch, *args):
531535
def start(self):
532536
"""register dispatchers for streams"""
533537
self.io_loop = ioloop.IOLoop.current()
534-
self.msg_queue: Queue[Any] = Queue()
538+
self.msg_queue: Queue[t.Any] = Queue()
535539
self.io_loop.add_callback(self.dispatch_queue)
536540

537541
self.control_stream.on_recv(self.dispatch_control, copy=False)
@@ -866,7 +870,7 @@ async def comm_info_request(self, stream, ident, parent):
866870
if hasattr(self, "comm_manager"):
867871
comms = {
868872
k: dict(target_name=v.target_name)
869-
for (k, v) in self.comm_manager.comms.items()
873+
for (k, v) in self.comm_manager.comms.items() # type:ignore[attr-defined]
870874
if v.target_name == target_name or target_name is None
871875
}
872876
else:

ipykernel/kernelspec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tempfile
1313

1414
from jupyter_client.kernelspec import KernelSpecManager
15+
from traitlets import Unicode
1516

1617
from .debugger import _is_debugpy_available
1718

@@ -161,7 +162,7 @@ def install(
161162
class InstallIPythonKernelSpecApp(Application):
162163
"""Dummy app wrapping argparse"""
163164

164-
name = "ipython-kernel-install"
165+
name = Unicode("ipython-kernel-install")
165166

166167
def initialize(self, argv=None):
167168
if argv is None:

0 commit comments

Comments
 (0)