Repository navigation
Deduplicate the optional FigureWidget import in graph_objects codegen - #5850
Open
DawnofGenX wants to merge 1 commit into
Open
DawnofGenX wants to merge 1 commit into
DawnofGenX wants to merge 1 commit into
Conversation
The code generator emitted the optional FigureWidget import block (try: import ipywidgets / missing_* fallback) into both plotly/graph_objs/__init__.py and plotly/graph_objects/__init__.py, producing an identical block at the end of each generated file. graph_objects already re-exports every other class from graph_objs (including Figure), and graph_objs owns the optional ipywidgets import and the missing_* fallback. Emit the block only for graph_objs and re-export FigureWidget from graph_objs in graph_objects like every other class. Behaviour is unchanged: plotly.graph_objects.FigureWidget still resolves to the real class when ipywidgets is present and to the missing_* fallback when it is absent. Add a regression test proving the invariant (identity, forced-failure fallback, and no duplicated ipywidgets block in graph_objects). Fixes plotly#5849
camdecoster
requested changes
Oct 27, 2026
camdecoster
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the update. Could you please make these changes?
Contributor
There was a problem hiding this comment.
Could you please remove this test? It seems like overkill.
Contributor
There was a problem hiding this comment.
Could you please revert these changes? This is an internal update and doesn't need a changelog entry.
Comment on lines
306
to
+314
| graph_objects_rel_classes = [ | ||
| "..graph_objs." + rel_path.split(".")[-1] | ||
| for rel_path in datatype_rel_class_imports[()] | ||
| ] | ||
| # FigureWidget is owned by graph_objs, which handles the optional | ||
| # ipywidgets import and the missing_* fallback. Re-export it from | ||
| # graph_objs like every other class instead of duplicating the optional | ||
| # import block in graph_objects. | ||
| graph_objects_rel_classes.append("..graph_objs.FigureWidget") |
Contributor
There was a problem hiding this comment.
Let's simplify this a bit:
Suggested change
| graph_objects_rel_classes.append("..graph_objs.FigureWidget") | |
| graph_objects_rel_classes = [ | |
| *("..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", | |
| ] |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Closes #5849
Description of change
The code generator wrote the optional
FigureWidgetimport block (thetry: import ...plus themissing_*fallback) into bothplotly/graph_objs/__init__.pyandplotly/graph_objects/__init__.py, leaving an identical block at the end of each generated file.graph_objectsre-exports every other class fromgraph_objs— includingFigure— andgraph_objsalready owns the optional import and the fallback, so the generator now emits the block only forgraph_objsand adds..graph_objs.FigureWidgettograph_objects' re-export list. The change is incodegen/__init__.py;plotly/graph_objects/__init__.pyis regenerated (python commands.py codegen), not hand-edited.Demo
N/A — no user-visible or visual change. Behaviour is unchanged:
plotly.graph_objects.FigureWidgetis the same object asplotly.graph_objs.FigureWidget, and still falls back toplotly.missing_anywidget.FigureWidgetwhenipywidgetsis unavailable.Testing strategy
Adds
tests/test_core/test_figure_widget_backend/test_figurewidget_reexport.py, which asserts the three invariants:graph_objects.FigureWidget is graph_objs.FigureWidget, the forced-ipywidgets-failure fallback still resolves, andplotly/graph_objects/__init__.pycontains no optional-ipywidgetsimport block of its own. The last assertion is the regression signal — it fails on unmodifiedmain.Additional information (optional)
Ran
python commands.py codegenon the committed tree with the pinned ruff and it produces no diff, so the generated file and the generator agree.Guidelines