Repository navigation
fix: keep isinstance(fig, go.Figure) working after register_plotly_resampler - #372
Open
raashish1601 wants to merge 1 commit into
Open
raashish1601 wants to merge 1 commit into
raashish1601 wants to merge 1 commit into
Conversation
…sampler (predict-idlab#364) register_plotly_resampler replaced go.Figure and go.FigureWidget with plain functions, so isinstance(fig, go.Figure) raised a TypeError. Replace them with classes whose metaclass forwards isinstance, issubclass and attribute lookups to the original plotly class. Fixes predict-idlab#364
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.
Fixes #364
register_plotly_resampler()replacedgo.Figureandgo.FigureWidgetwith plain functions. That madeisinstance(fig, go.Figure)raiseTypeError: isinstance() arg 2 must be a type..., which breaks any downstream code that checks figure types.The wrappers are now small classes instead of functions. Calling one still returns a
FigureResampler/FigureWidgetResamplerexactly as before (__new__builds it, so__init__never runs). Their metaclass forwardsisinstance,issubclassand class attribute lookups to the original plotly class. So after registering,isinstance(fig, go.Figure)isTrue,issubclass(FigureResampler, go.Figure)isTrue, andgo.Figure.<attr>still works like it did with thefunctools.wrapsfunction. Unregistering and_get_plotly_constrwork the same way through__wrapped__.Tests: added
test_isinstance_when_registeredtotests/test_registering.py. It covers figure and widget mode,issubclass, and checks after unregistering. The existing tests asserted that the registered constructors are functions (inspect.isfunction), so they now use_already_wrappedinstead.test_registering.py,test_composability.pyandtest_plotly_express.pypass. Intest_serialization.py, the three FigureWidget copy tests fail locally both with and without this change, because my env has ipywidgets 8 (Widgets cannot be copied) and the project pins 7.ruff checkandblack --checkare clean.I also added a line to the "Latest" section of the changelog.