From 515004a331b10dff026b8d81a0571e4cdf1847a3 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 3 Oct 2023 19:37:45 -0500 Subject: [PATCH] Update typing for traitlets 5.11 (#1154) --- ipykernel/embed.py | 2 +- ipykernel/inprocess/blocking.py | 6 +++--- ipykernel/inprocess/client.py | 22 ++++++++++++---------- ipykernel/inprocess/ipkernel.py | 2 +- ipykernel/ipkernel.py | 14 +++++++------- ipykernel/kernelapp.py | 6 +++--- ipykernel/zmqshell.py | 18 +++++++++--------- pyproject.toml | 2 +- 8 files changed, 37 insertions(+), 35 deletions(-) diff --git a/ipykernel/embed.py b/ipykernel/embed.py index de208eb2..3e4abd39 100644 --- a/ipykernel/embed.py +++ b/ipykernel/embed.py @@ -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() diff --git a/ipykernel/inprocess/blocking.py b/ipykernel/inprocess/blocking.py index f09bb231..c598a44b 100644 --- a/ipykernel/inprocess/blocking.py +++ b/ipykernel/inprocess/blocking.py @@ -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.""" diff --git a/ipykernel/inprocess/client.py b/ipykernel/inprocess/client.py index 0c4a1967..d0ebfd22 100644 --- a/ipykernel/inprocess/client.py +++ b/ipykernel/inprocess/client.py @@ -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) @@ -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 diff --git a/ipykernel/inprocess/ipkernel.py b/ipykernel/inprocess/ipkernel.py index 30daca88..13b17217 100644 --- a/ipykernel/inprocess/ipkernel.py +++ b/ipykernel/inprocess/ipkernel.py @@ -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] diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py index 990c5558..58821850 100644 --- a/ipykernel/ipkernel.py +++ b/ipykernel/ipkernel.py @@ -118,7 +118,7 @@ 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, @@ -126,21 +126,21 @@ def __init__(self, **kwargs): 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) diff --git a/ipykernel/kernelapp.py b/ipykernel/kernelapp.py index 483f3844..dae72def 100644 --- a/ipykernel/kernelapp.py +++ b/ipykernel/kernelapp.py @@ -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. diff --git a/ipykernel/zmqshell.py b/ipykernel/zmqshell.py index c4b2e312..617c37a6 100644 --- a/ipykernel/zmqshell.py +++ b/ipykernel/zmqshell.py @@ -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 @@ -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, ) @@ -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: diff --git a/pyproject.toml b/pyproject.toml index ae96b102..f34c5482 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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}"