From fb1aa4d1f53e0491a88ee8b6b36c797d2d232c6b Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 10 Feb 2023 10:36:14 +0100 Subject: [PATCH] Backward compat --- python/ipywidgets/ipywidgets/__init__.py | 8 +++++++- python/ipywidgets/ipywidgets/widgets/widget.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/python/ipywidgets/ipywidgets/__init__.py b/python/ipywidgets/ipywidgets/__init__.py index 04b27494c0..9b51408499 100644 --- a/python/ipywidgets/ipywidgets/__init__.py +++ b/python/ipywidgets/ipywidgets/__init__.py @@ -23,7 +23,13 @@ import os from traitlets import link, dlink -from comm import get_comm_manager +try: + from comm import get_comm_manager +except ImportError: + def get_comm_manager(): + from IPython import get_ipython + + return get_ipython().kernel.comm_manager from .widgets import * diff --git a/python/ipywidgets/ipywidgets/widgets/widget.py b/python/ipywidgets/ipywidgets/widgets/widget.py index 0c0492171a..3befc7ac52 100644 --- a/python/ipywidgets/ipywidgets/widgets/widget.py +++ b/python/ipywidgets/ipywidgets/widgets/widget.py @@ -10,7 +10,13 @@ from contextlib import contextmanager from collections.abc import Iterable from IPython import get_ipython -from comm import create_comm +try: + from comm import create_comm +except ImportError: + from ipykernel.comm import Comm + + def create_comm(**kwargs): + return Comm(**kwargs) from traitlets import ( Any, HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container, Undefined)