Skip to content

Commit c5a045f

Browse files
maartenbreddelspre-commit-ci[bot]blink1073
authored
fix: use comm package in backwards compatible way (#1028)
* fix: use comm package in backwards compatible way * feat: do not use the LoggingConfigurable class in create_comm * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
1 parent 747259c commit c5a045f

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

ipykernel/comm/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
__all__ = ["Comm", "CommManager"]
22

3-
from comm.base_comm import CommManager # noqa
4-
53
from .comm import Comm # noqa
4+
from .manager import CommManager

ipykernel/comm/comm.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
# Copyright (c) IPython Development Team.
44
# Distributed under the terms of the Modified BSD License.
55

6-
from comm.base_comm import BaseComm
6+
from typing import Optional
7+
8+
import comm.base_comm
9+
import traitlets.config
710

811
from ipykernel.jsonutil import json_clean
912
from ipykernel.kernelbase import Kernel
1013

1114

12-
class Comm(BaseComm):
13-
"""Class for communicating between a Frontend and a Kernel"""
14-
15-
def __init__(self, *args, **kwargs):
16-
self.kernel = None
17-
18-
super().__init__(*args, **kwargs)
15+
# this is the class that will be created if we do comm.create_comm
16+
class BaseComm(comm.base_comm.BaseComm):
17+
kernel: Optional[Kernel]
1918

2019
def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
2120
"""Helper for sending a comm message on IOPub"""
@@ -40,4 +39,15 @@ def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
4039
)
4140

4241

42+
# but for backwards compatibility, we need to inherit from LoggingConfigurable
43+
class Comm(traitlets.config.LoggingConfigurable, BaseComm):
44+
"""Class for communicating between a Frontend and a Kernel"""
45+
46+
def __init__(self, *args, **kwargs):
47+
self.kernel = None
48+
# Comm takes positional arguments, LoggingConfigurable does not, so we explicitly forward arguments
49+
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
50+
BaseComm.__init__(self, *args, **kwargs)
51+
52+
4353
__all__ = ["Comm"]

ipykernel/comm/manager.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,13 @@
33
# Copyright (c) IPython Development Team.
44
# Distributed under the terms of the Modified BSD License.
55

6-
from comm.base_comm import CommManager # noqa
6+
7+
import comm.base_comm
8+
import traitlets.config
9+
10+
11+
class CommManager(traitlets.config.LoggingConfigurable, comm.base_comm.CommManager):
12+
def __init__(self, **kwargs):
13+
# CommManager doesn't take arguments, so we explicitly forward arguments
14+
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
15+
comm.base_comm.CommManager.__init__(self)

ipykernel/ipkernel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from traitlets import Any, Bool, Instance, List, Type, observe, observe_compat
1616
from zmq.eventloop.zmqstream import ZMQStream
1717

18-
from .comm import Comm
18+
from .comm.comm import BaseComm
1919
from .compiler import XCachingCompiler
2020
from .debugger import Debugger, _is_debugpy_available
2121
from .eventloops import _use_appnope
@@ -42,7 +42,7 @@
4242

4343
def create_comm(*args, **kwargs):
4444
"""Create a new Comm."""
45-
return Comm(*args, **kwargs)
45+
return BaseComm(*args, **kwargs)
4646

4747

4848
comm.create_comm = create_comm

0 commit comments

Comments
 (0)