Skip to content

Commit

Permalink
feat: do not use the LoggingConfigurable class in create_comm
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Nov 23, 2022
1 parent 736cb99 commit 5032761
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 14 additions & 10 deletions ipykernel/comm/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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"]
3 changes: 2 additions & 1 deletion ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5032761

Please sign in to comment.