From 514495a25eb327983a2942b6f9a605a725b4892e Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Thu, 8 Dec 2022 11:09:18 +0100 Subject: [PATCH 1/2] fix: too many arguments dropped when passing to base comm constructor Bug introduced in fee98e5, covered by test now. Closes #1050 --- ipykernel/comm/comm.py | 3 ++- ipykernel/tests/test_comm.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ipykernel/comm/comm.py b/ipykernel/comm/comm.py index c06d233bb..5fb6d14c2 100644 --- a/ipykernel/comm/comm.py +++ b/ipykernel/comm/comm.py @@ -71,7 +71,8 @@ def _default_comm_id(self): def __init__(self, *args, **kwargs): # Comm takes positional arguments, LoggingConfigurable does not, so we explicitly forward arguments traitlets.config.LoggingConfigurable.__init__(self, **kwargs) - for name in self.trait_names(): + # drop arguments not in BaseComm + for name in ["kernel"]: if name in kwargs: kwargs.pop(name) BaseComm.__init__(self, *args, **kwargs) diff --git a/ipykernel/tests/test_comm.py b/ipykernel/tests/test_comm.py index 9dd49f82e..f8b076413 100644 --- a/ipykernel/tests/test_comm.py +++ b/ipykernel/tests/test_comm.py @@ -6,7 +6,7 @@ def test_comm(kernel): manager = CommManager(kernel=kernel) kernel.comm_manager = manager - c = Comm(kernel=kernel) + c = Comm(kernel=kernel, target_name="bar") msgs = [] def on_close(msg): @@ -23,6 +23,7 @@ def on_message(msg): c.handle_close({}) c.close() assert len(msgs) == 2 + assert c.target_name == "bar" def test_comm_manager(kernel): From 3cf49c870da2129fc7189203f04fec44aa48db1e Mon Sep 17 00:00:00 2001 From: Maarten Breddels Date: Thu, 8 Dec 2022 11:27:02 +0100 Subject: [PATCH 2/2] simplify code Co-authored-by: martinRenou --- ipykernel/comm/comm.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ipykernel/comm/comm.py b/ipykernel/comm/comm.py index 5fb6d14c2..295232e14 100644 --- a/ipykernel/comm/comm.py +++ b/ipykernel/comm/comm.py @@ -72,9 +72,7 @@ def __init__(self, *args, **kwargs): # Comm takes positional arguments, LoggingConfigurable does not, so we explicitly forward arguments traitlets.config.LoggingConfigurable.__init__(self, **kwargs) # drop arguments not in BaseComm - for name in ["kernel"]: - if name in kwargs: - kwargs.pop(name) + kwargs.pop("kernel", None) BaseComm.__init__(self, *args, **kwargs)