From c43ee1987a9ce1c76353524d617f6fc76f47fbdb Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 22 Oct 2023 09:55:11 -0500 Subject: [PATCH] cleanup --- ipykernel/connect.py | 6 ++++-- ipykernel/kernelapp.py | 1 + ipykernel/kernelspec.py | 6 +++--- ipykernel/zmqshell.py | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ipykernel/connect.py b/ipykernel/connect.py index 9ca7867a..3336ced0 100644 --- a/ipykernel/connect.py +++ b/ipykernel/connect.py @@ -50,7 +50,9 @@ def _find_connection_file(connection_file): return jupyter_client.find_connection_file(connection_file) -def get_connection_info(connection_file: str | None = None, unpack: bool = False) -> str: +def get_connection_info( + connection_file: str | None = None, unpack: bool = False +) -> str | dict[str, Any]: """Return the connection information for the current Kernel. Parameters @@ -81,7 +83,7 @@ def get_connection_info(connection_file: str | None = None, unpack: bool = False info = json.loads(info_str) # ensure key is bytes: info["key"] = info.get("key", "").encode() - return info + return info # type:ignore[no-any-return] return info_str diff --git a/ipykernel/kernelapp.py b/ipykernel/kernelapp.py index dae72def..de4682f8 100644 --- a/ipykernel/kernelapp.py +++ b/ipykernel/kernelapp.py @@ -275,6 +275,7 @@ def write_connection_file(self): # original file had port number 0, we update with the actual port # used. existing_connection_info = get_connection_info(cf, unpack=True) + assert isinstance(existing_connection_info, dict) connection_info = dict(existing_connection_info, **connection_info) if connection_info == existing_connection_info: self.log.debug("Connection file %s with current information already exists", cf) diff --git a/ipykernel/kernelspec.py b/ipykernel/kernelspec.py index eb3ac49e..6404c2a1 100644 --- a/ipykernel/kernelspec.py +++ b/ipykernel/kernelspec.py @@ -111,7 +111,7 @@ def install( prefix: str | None = None, profile: str | None = None, env: dict[str, str] | None = None, -): +) -> str: """Install the IPython kernelspec for Jupyter Parameters @@ -147,7 +147,7 @@ def install( # kernel_name is specified and display_name is not # default display_name to kernel_name display_name = kernel_name - overrides = {} + overrides: dict[str, Any] = {} if display_name: overrides["display_name"] = display_name if profile: @@ -165,7 +165,7 @@ def install( ) # cleanup afterward shutil.rmtree(path) - return dest + return dest # type:ignore[no-any-return] # Entrypoint diff --git a/ipykernel/zmqshell.py b/ipykernel/zmqshell.py index 617c37a6..d381a5c9 100644 --- a/ipykernel/zmqshell.py +++ b/ipykernel/zmqshell.py @@ -378,6 +378,7 @@ def connect_info(self, arg_s): if jupyter_runtime_dir() == os.path.dirname(connection_file): connection_file = os.path.basename(connection_file) + assert isinstance(info, str) print(info + "\n") print( f"Paste the above JSON into a file, and connect with:\n"