diff --git a/ipykernel/comm/comm.py b/ipykernel/comm/comm.py index 1f9a39d70..d6463219d 100644 --- a/ipykernel/comm/comm.py +++ b/ipykernel/comm/comm.py @@ -4,21 +4,14 @@ # Distributed under the terms of the Modified BSD License. import traitlets.config -from comm.base_comm import BaseComm - from ipykernel.jsonutil import json_clean from ipykernel.kernelbase import Kernel +import comm.base_comm -class Comm(traitlets.config.LoggingConfigurable, BaseComm): - """Class for communicating between a Frontend and a Kernel""" - - def __init__(self, *args, **kwargs): - self.kernel = None - # Comm takes positional arguments, LoggingConfigurable does not, so we explicitly forward arguments - traitlets.config.LoggingConfigurable.__init__(self, **kwargs) - BaseComm.__init__(self, *args, **kwargs) +# this is the class that will be created if we do comm.create_comm +class BaseComm(comm.base_comm.BaseComm): def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys): """Helper for sending a comm message on IOPub""" if not Kernel.initialized(): @@ -42,4 +35,15 @@ def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys): ) +# but for backwards compatibility, we need to inherit from LoggingConfigurable +class Comm(traitlets.config.LoggingConfigurable, BaseComm): + """Class for communicating between a Frontend and a Kernel""" + + def __init__(self, *args, **kwargs): + self.kernel = None + # Comm takes positional arguments, LoggingConfigurable does not, so we explicitly forward arguments + traitlets.config.LoggingConfigurable.__init__(self, **kwargs) + BaseComm.__init__(self, *args, **kwargs) + + __all__ = ["Comm"] diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py index c16cc0ed5..26475f30f 100644 --- a/ipykernel/ipkernel.py +++ b/ipykernel/ipkernel.py @@ -42,7 +42,8 @@ def create_comm(*args, **kwargs): """Create a new Comm.""" - return Comm(*args, **kwargs) + from .comm.comm import BaseComm + return BaseComm(*args, **kwargs) comm.create_comm = create_comm