From 29cf2e7a81092fc290f44beeda6b242750fe463f Mon Sep 17 00:00:00 2001 From: bsundaram1 <119066328+bsundaram1@users.noreply.github.com> Date: Wed, 2 Apr 2025 19:29:24 -0700 Subject: [PATCH 1/3] Convert str to bytes for comparing 'key' Making sure that the key named 'key' is consistently bytes across the values returned by KernelManager and the provisioner. --- jupyter_client/connect.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index f5d54550..a1094625 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -615,6 +615,20 @@ def _reconcile_connection_info(self, info: KernelConnectionInfo) -> None: def _equal_connections(conn1: KernelConnectionInfo, conn2: KernelConnectionInfo) -> bool: """Compares pertinent keys of connection info data. Returns True if equivalent, False otherwise.""" + def _normalize_connection_info_keys(conn1, conn2): + """ + Ensure 'key' values in both conn1 and conn2 are bytes before comparison. + Modifies conn1 and conn2 in-place. + """ + key = "key" + val1 = conn1.get(key) + val2 = conn2.get(key) + + if isinstance(val1, str) and isinstance(val2, bytes): + conn1[key] = val1.encode("utf-8") + elif isinstance(val1, bytes) and isinstance(val2, str): + conn2[key] = val2.encode("utf-8") + pertinent_keys = [ "key", "ip", @@ -627,6 +641,7 @@ def _equal_connections(conn1: KernelConnectionInfo, conn2: KernelConnectionInfo) "signature_scheme", ] + _normalize_connection_info_keys(conn1, conn2) return all(conn1.get(key) == conn2.get(key) for key in pertinent_keys) # -------------------------------------------------------------------------- From a8c29c883596b10b290cf15a432afd2842d49a90 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 02:31:40 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- jupyter_client/connect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index a1094625..e8a44c6f 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -623,12 +623,12 @@ def _normalize_connection_info_keys(conn1, conn2): key = "key" val1 = conn1.get(key) val2 = conn2.get(key) - + if isinstance(val1, str) and isinstance(val2, bytes): conn1[key] = val1.encode("utf-8") elif isinstance(val1, bytes) and isinstance(val2, str): conn2[key] = val2.encode("utf-8") - + pertinent_keys = [ "key", "ip", From d6cf970d04a48de30225259b160ea3c5d3ec1d81 Mon Sep 17 00:00:00 2001 From: bsundaram1 <119066328+bsundaram1@users.noreply.github.com> Date: Wed, 2 Apr 2025 19:35:44 -0700 Subject: [PATCH 3/3] Fix indent --- jupyter_client/connect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index e8a44c6f..81e6b1c7 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -616,10 +616,10 @@ def _equal_connections(conn1: KernelConnectionInfo, conn2: KernelConnectionInfo) """Compares pertinent keys of connection info data. Returns True if equivalent, False otherwise.""" def _normalize_connection_info_keys(conn1, conn2): - """ - Ensure 'key' values in both conn1 and conn2 are bytes before comparison. - Modifies conn1 and conn2 in-place. - """ + """ + Ensure 'key' values in both conn1 and conn2 are bytes before comparison. + Modifies conn1 and conn2 in-place. + """ key = "key" val1 = conn1.get(key) val2 = conn2.get(key)