Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ repos:
- id: mypy
exclude: "ipykernel.*tests"
args: ["--config-file", "pyproject.toml"]
additional_dependencies: [tornado, jupyter_client, pytest]
additional_dependencies:
[tornado, jupyter_client, pytest, traitlets, jupyter_core]
stages: [manual]

- repo: https://github.com/pycqa/flake8
Expand Down
11 changes: 7 additions & 4 deletions ipykernel/inprocess/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class InProcessKernel(IPythonKernel):

shell_class = Type(allow_none=True)
_underlying_iopub_socket = Instance(DummySocket, ())
iopub_thread = Instance(IOPubThread)
iopub_thread: IOPubThread = Instance(IOPubThread) # type:ignore[assignment]

shell_stream = Instance(DummySocket, ())

Expand All @@ -58,13 +58,13 @@ def _default_iopub_thread(self):
thread.start()
return thread

iopub_socket = Instance(BackgroundSocket)
iopub_socket: BackgroundSocket = Instance(BackgroundSocket) # type:ignore[assignment]

@default("iopub_socket")
def _default_iopub_socket(self):
return self.iopub_thread.background_socket

stdin_socket = Instance(DummySocket, ())
stdin_socket = Instance(DummySocket, ()) # type:ignore[assignment]

def __init__(self, **traits):
super().__init__(**traits)
Expand Down Expand Up @@ -127,6 +127,7 @@ def _redirected_io(self):

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

class InProcessInteractiveShell(ZMQInteractiveShell):

kernel = Instance("ipykernel.inprocess.ipkernel.InProcessKernel", allow_none=True)
kernel: InProcessKernel = Instance(
"ipykernel.inprocess.ipkernel.InProcessKernel", allow_none=True
) # type:ignore[assignment]

# -------------------------------------------------------------------------
# InteractiveShell interface
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from jupyter_client.session import Session, session_aliases, session_flags
from jupyter_core.paths import jupyter_runtime_dir
from tornado import ioloop
from traitlets import (
from traitlets.traitlets import (
Any,
Bool,
Dict,
Expand Down
16 changes: 10 additions & 6 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
from jupyter_client.session import Session
from tornado import ioloop
from tornado.queues import Queue, QueueEmpty
from traitlets import (
from traitlets.config.configurable import SingletonConfigurable
from traitlets.traitlets import (
Any,
Bool,
Dict,
Expand All @@ -51,7 +52,6 @@
default,
observe,
)
from traitlets.config.configurable import SingletonConfigurable
from zmq.eventloop.zmqstream import ZMQStream

from ipykernel.jsonutil import json_clean
Expand Down Expand Up @@ -95,6 +95,10 @@ def _update_eventloop(self, change):
"""
)

implementation: str
implementation_version: str
banner: str

@default("shell_streams")
def _shell_streams_default(self):
warnings.warn(
Expand Down Expand Up @@ -131,7 +135,7 @@ def _shell_streams_changed(self, change):
iopub_socket = Any()
iopub_thread = Any()
stdin_socket = Any()
log = Instance(logging.Logger, allow_none=True)
log: logging.Logger = Instance(logging.Logger, allow_none=True) # type:ignore[assignment]

# identities:
int_id = Integer(-1)
Expand Down Expand Up @@ -263,7 +267,7 @@ def __init__(self, **kwargs):
for msg_type in self.control_msg_types:
self.control_handlers[msg_type] = getattr(self, msg_type)

self.control_queue: Queue[Any] = Queue()
self.control_queue: Queue[t.Any] = Queue()

def dispatch_control(self, msg):
self.control_queue.put_nowait(msg)
Expand Down Expand Up @@ -531,7 +535,7 @@ def schedule_dispatch(self, dispatch, *args):
def start(self):
"""register dispatchers for streams"""
self.io_loop = ioloop.IOLoop.current()
self.msg_queue: Queue[Any] = Queue()
self.msg_queue: Queue[t.Any] = Queue()
self.io_loop.add_callback(self.dispatch_queue)

self.control_stream.on_recv(self.dispatch_control, copy=False)
Expand Down Expand Up @@ -866,7 +870,7 @@ async def comm_info_request(self, stream, ident, parent):
if hasattr(self, "comm_manager"):
comms = {
k: dict(target_name=v.target_name)
for (k, v) in self.comm_manager.comms.items()
for (k, v) in self.comm_manager.comms.items() # type:ignore[attr-defined]
if v.target_name == target_name or target_name is None
}
else:
Expand Down
3 changes: 2 additions & 1 deletion ipykernel/kernelspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import tempfile

from jupyter_client.kernelspec import KernelSpecManager
from traitlets import Unicode

from .debugger import _is_debugpy_available

Expand Down Expand Up @@ -161,7 +162,7 @@ def install(
class InstallIPythonKernelSpecApp(Application):
"""Dummy app wrapping argparse"""

name = "ipython-kernel-install"
name = Unicode("ipython-kernel-install")

def initialize(self, argv=None):
if argv is None:
Expand Down