diff --git a/codegen/__init__.py b/codegen/__init__.py index b299fa36045..57b7b2d6f24 100644 --- a/codegen/__init__.py +++ b/codegen/__init__.py @@ -304,8 +304,12 @@ def __getattr__(import_name): # Output graph_objects.py alias graph_objects_rel_classes = [ - "..graph_objs." + rel_path.split(".")[-1] - for rel_path in datatype_rel_class_imports[()] + *( + "..graph_objs." + rel_path.split(".")[-1] + for rel_path in datatype_rel_class_imports[()] + ), + # graph_objs owns the optional ipywidgets import and the fallback + "..graph_objs.FigureWidget", ] graph_objects_rel_modules = [ "..graph_objs." + rel_module.split(".")[-1] @@ -315,7 +319,6 @@ def __getattr__(import_name): graph_objects_init_source = build_from_imports_py( graph_objects_rel_modules, graph_objects_rel_classes, - init_extra=optional_figure_widget_import, ) graph_objects_path = opath.join(outdir, "graph_objects", "__init__.py") os.makedirs(opath.join(outdir, "graph_objects"), exist_ok=True) diff --git a/plotly/graph_objects/__init__.py b/plotly/graph_objects/__init__.py index 670e4b8c6a1..919f804085d 100644 --- a/plotly/graph_objects/__init__.py +++ b/plotly/graph_objects/__init__.py @@ -77,6 +77,7 @@ from ..graph_objs import YBins from ..graph_objs import Trace from ..graph_objs import Histogram2dcontour + from ..graph_objs import FigureWidget from ..graph_objs import waterfall from ..graph_objs import volume from ..graph_objs import violin @@ -255,42 +256,6 @@ "..graph_objs.YBins", "..graph_objs.Trace", "..graph_objs.Histogram2dcontour", + "..graph_objs.FigureWidget", ], ) - - -if sys.version_info < (3, 7) or TYPE_CHECKING: - try: - import ipywidgets as _ipywidgets - from packaging.version import Version as _Version - - if _Version(_ipywidgets.__version__) >= _Version("7.0.0"): - from ..graph_objs._figurewidget import FigureWidget - else: - raise ImportError() - except Exception: - from ..missing_anywidget import FigureWidget -else: - __all__.append("FigureWidget") - orig_getattr = __getattr__ - - def __getattr__(import_name): - if import_name == "FigureWidget": - try: - import ipywidgets - from packaging.version import Version - - if Version(ipywidgets.__version__) >= Version("7.0.0"): - from ..graph_objs._figurewidget import FigureWidget - - return FigureWidget - else: - raise ImportError() - except Exception: - from ..missing_anywidget import FigureWidget - - return FigureWidget - else: - raise ImportError() - - return orig_getattr(import_name)