Skip to content

Commit

Permalink
Update typing for traitlets 5.11 (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Oct 4, 2023
1 parent 11d7a33 commit 515004a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ipykernel/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ def embed_kernel(module=None, local_ns=None, **kwargs):

app.kernel.user_module = module
app.kernel.user_ns = local_ns
app.shell.set_completer_frame()
app.shell.set_completer_frame() # type:ignore[union-attr]
app.start()
6 changes: 3 additions & 3 deletions ipykernel/inprocess/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class BlockingInProcessKernelClient(InProcessKernelClient):
"""A blocking in-process kernel client."""

# The classes to use for the various channels.
shell_channel_class = Type(BlockingInProcessChannel)
iopub_channel_class = Type(BlockingInProcessChannel)
stdin_channel_class = Type(BlockingInProcessStdInChannel)
shell_channel_class = Type(BlockingInProcessChannel) # type:ignore[arg-type]
iopub_channel_class = Type(BlockingInProcessChannel) # type:ignore[arg-type]
stdin_channel_class = Type(BlockingInProcessStdInChannel) # type:ignore[arg-type]

def wait_for_ready(self):
"""Wait for kernel info reply on shell channel."""
Expand Down
22 changes: 12 additions & 10 deletions ipykernel/inprocess/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class InProcessKernelClient(KernelClient):
"""

# The classes to use for the various channels.
shell_channel_class = Type(InProcessChannel)
iopub_channel_class = Type(InProcessChannel)
stdin_channel_class = Type(InProcessChannel)
control_channel_class = Type(InProcessChannel)
hb_channel_class = Type(InProcessHBChannel)
shell_channel_class = Type(InProcessChannel) # type:ignore[arg-type]
iopub_channel_class = Type(InProcessChannel) # type:ignore[arg-type]
stdin_channel_class = Type(InProcessChannel) # type:ignore[arg-type]
control_channel_class = Type(InProcessChannel) # type:ignore[arg-type]
hb_channel_class = Type(InProcessHBChannel) # type:ignore[arg-type]

kernel = Instance("ipykernel.inprocess.ipkernel.InProcessKernel", allow_none=True)

Expand Down Expand Up @@ -72,31 +72,33 @@ def start_channels(self, *args, **kwargs):
@property
def shell_channel(self):
if self._shell_channel is None:
self._shell_channel = self.shell_channel_class(self) # type:ignore[operator]
self._shell_channel = self.shell_channel_class(self) # type:ignore[abstract,call-arg]
return self._shell_channel

@property
def iopub_channel(self):
if self._iopub_channel is None:
self._iopub_channel = self.iopub_channel_class(self) # type:ignore[operator]
self._iopub_channel = self.iopub_channel_class(self) # type:ignore[abstract,call-arg]
return self._iopub_channel

@property
def stdin_channel(self):
if self._stdin_channel is None:
self._stdin_channel = self.stdin_channel_class(self) # type:ignore[operator]
self._stdin_channel = self.stdin_channel_class(self) # type:ignore[abstract,call-arg]
return self._stdin_channel

@property
def control_channel(self):
if self._control_channel is None:
self._control_channel = self.control_channel_class(self) # type:ignore[operator]
self._control_channel = self.control_channel_class(
self
) # type:ignore[abstract,call-arg]
return self._control_channel

@property
def hb_channel(self):
if self._hb_channel is None:
self._hb_channel = self.hb_channel_class(self) # type:ignore[operator]
self._hb_channel = self.hb_channel_class(self) # type:ignore[abstract,call-arg]
return self._hb_channel

# Methods for sending specific messages
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/inprocess/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InProcessKernel(IPythonKernel):
# Kernel interface
# -------------------------------------------------------------------------

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

Expand Down
14 changes: 7 additions & 7 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,29 @@ def __init__(self, **kwargs):
)

# Initialize the InteractiveShell subclass
self.shell = self.shell_class.instance( # type:ignore[attr-defined]
self.shell = self.shell_class.instance(
parent=self,
profile_dir=self.profile_dir,
user_module=self.user_module,
user_ns=self.user_ns,
kernel=self,
compiler_class=XCachingCompiler,
)
self.shell.displayhook.session = self.session
self.shell.displayhook.session = self.session # type:ignore[attr-defined]

jupyter_session_name = os.environ.get('JPY_SESSION_NAME')
if jupyter_session_name:
self.shell.user_ns['__session__'] = jupyter_session_name

self.shell.displayhook.pub_socket = self.iopub_socket
self.shell.displayhook.topic = self._topic("execute_result")
self.shell.display_pub.session = self.session
self.shell.display_pub.pub_socket = self.iopub_socket
self.shell.displayhook.pub_socket = self.iopub_socket # type:ignore[attr-defined]
self.shell.displayhook.topic = self._topic("execute_result") # type:ignore[attr-defined]
self.shell.display_pub.session = self.session # type:ignore[attr-defined]
self.shell.display_pub.pub_socket = self.iopub_socket # type:ignore[attr-defined]

self.comm_manager = comm.get_comm_manager()

assert isinstance(self.comm_manager, HasTraits)
self.shell.configurables.append(self.comm_manager)
self.shell.configurables.append(self.comm_manager) # type:ignore[arg-type]
comm_msg_types = ["comm_open", "comm_msg", "comm_close"]
for msg_type in comm_msg_types:
self.shell_handlers[msg_type] = getattr(self.comm_manager, msg_type)
Expand Down
6 changes: 3 additions & 3 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@
)

# inherit flags&aliases for any IPython shell apps
kernel_aliases.update(shell_aliases) # type:ignore[arg-type]
kernel_aliases.update(shell_aliases)
kernel_flags.update(shell_flags)

# inherit flags&aliases for Sessions
kernel_aliases.update(session_aliases) # type:ignore[arg-type]
kernel_flags.update(session_flags) # type:ignore[arg-type]
kernel_aliases.update(session_aliases)
kernel_flags.update(session_flags)

_ctrl_c_message = """\
NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.
Expand Down
18 changes: 9 additions & 9 deletions ipykernel/zmqshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ def data_pub(self):
)

self._data_pub = self.data_pub_class(parent=self) # type:ignore[has-type]
self._data_pub.session = self.display_pub.session
self._data_pub.pub_socket = self.display_pub.pub_socket
self._data_pub.session = self.display_pub.session # type:ignore[attr-defined]
self._data_pub.pub_socket = self.display_pub.pub_socket # type:ignore[attr-defined]
return self._data_pub

@data_pub.setter
Expand Down Expand Up @@ -562,14 +562,14 @@ def _showtraceback(self, etype, evalue, stb):
# Send exception info over pub socket for other clients than the caller
# to pick up
topic = None
if dh.topic:
topic = dh.topic.replace(b"execute_result", b"error")
if dh.topic: # type:ignore[attr-defined]
topic = dh.topic.replace(b"execute_result", b"error") # type:ignore[attr-defined]

dh.session.send(
dh.pub_socket,
dh.session.send( # type:ignore[attr-defined]
dh.pub_socket, # type:ignore[attr-defined]
"error",
json_clean(exc_content),
dh.parent_header,
dh.parent_header, # type:ignore[attr-defined]
ident=topic,
)

Expand All @@ -590,8 +590,8 @@ def set_next_input(self, text, replace=False):
def set_parent(self, parent):
"""Set the parent header for associating output with its triggering input"""
self.parent_header = parent
self.displayhook.set_parent(parent)
self.display_pub.set_parent(parent)
self.displayhook.set_parent(parent) # type:ignore[attr-defined]
self.display_pub.set_parent(parent) # type:ignore[attr-defined]
if hasattr(self, "_data_pub"):
self.data_pub.set_parent(parent)
try:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ matrix.qt.features = [

[tool.hatch.envs.typing]
features = ["test"]
dependencies = ["mypy>=1.5.1", "traitlets>=5.10.1"]
dependencies = ["mypy>=1.5.1", "traitlets>=5.11.2", "ipython>=8.16.1"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args}"

Expand Down

0 comments on commit 515004a

Please sign in to comment.