Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default pack_models #3738

Merged

Conversation

bollwyvl
Copy link
Contributor

@bollwyvl bollwyvl commented Mar 24, 2023

References

Changes

  • hoists critical IPY_MODEL_ magic string to a constant
  • removes some anonymous function definitions in (recursive) loops in unpack_models
  • adds pack_models
    • uses for any unset-serializer that's a neighbor of deserialize: unpack_models
  • makes use of the frozen JSONExt.emptyObject in some places to avoid allocating new objects

Questions

  • does it need to be a promise?
  • throw a warning?
    • ick. these get called a lot. maybe call once per class?
  • hoist widget_serialization to mirror the backend API?

@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch bollwyvl/ipywidgets/gh-3735-default-serializer

@bollwyvl
Copy link
Contributor Author

This does appear to fix at least ipytree and the jslink condition:

image

@bollwyvl bollwyvl marked this pull request as ready for review March 24, 2023 17:20
@bollwyvl bollwyvl changed the title Strawman default pack_models Add default pack_models Mar 24, 2023
@bollwyvl
Copy link
Contributor Author

I've taken this out of draft and updated the notes a bit: probably don't have time to dig into the packaging file... more node, more problems.

@@ -9,10 +9,3 @@ pandas
scikit-image
scikit-learn
sympy

# checking https://github.com/jupyter-widgets/ipywidgets/issues/3735
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed these here, and opened this issue: jupyter-widgets/team-compass#20

@maartenbreddels
Copy link
Member

@bollwyvl thank you for taking a look at this!

I wonder if instead of having a pack_models implementation, we should use the "old" JSON.parse(JSON.stringify(x))) method instead. We may be breaking code that relies on the toJSON option, what do you think of that?

I'll see if I can at least add a test to make this not happen again.

@maartenbreddels
Copy link
Member

In code, what I propose:

-const deepcopy =
-  globalThis.structuredClone || ((x: any) => JSON.parse(JSON.stringify(x)));
+const deepcopyJSON = (x: JSONValue) => JSON.parse(JSON.stringify(x));
+
+const deepcopy = globalThis.structuredClone || deepcopyJSON;
@@ -572,7 +574,7 @@ export class WidgetModel extends Backbone.Model {
 
         if (serialize == null && keySerializers.deserialize === unpack_models) {
           // handle https://github.com/jupyter-widgets/ipywidgets/issues/3735
-          serialize = pack_models;
+          serialize = deepcopyJSON;

I do like you pack_models and I think we should ship it, and use it, so we don't rely on the JSON trick in the ipywidget code base. This asymmetry has confused me many many times.

@bollwyvl
Copy link
Contributor Author

I can't push at the moment, due to github issues (last tried a few minutes ago) but i'm up for anything that reduces active breakage in many downstreams. Feel free to continue/fork this however you can!

@maartenbreddels maartenbreddels force-pushed the gh-3735-default-serializer branch 2 times, most recently from 1c8621a to 48a4cb6 Compare March 27, 2023 15:03
@maartenbreddels maartenbreddels merged commit 022b454 into jupyter-widgets:main Mar 28, 2023
@maartenbreddels
Copy link
Member

meeseeksdev please backport to 7.x

@lumberbot-app
Copy link

lumberbot-app bot commented Mar 28, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 7.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 022b4541c0cf848472993be48f13830ca71bfcac
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #3738: Add default `pack_models`'
  1. Push to a named branch:
git push YOURFORK 7.x:auto-backport-of-pr-3738-on-7.x
  1. Create a PR against branch 7.x, I would have named this PR:

"Backport PR #3738 on branch 7.x (Add default pack_models)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

* However, the default serialize method will have the same effect, when
* `unpack_models` is used as the deserialize method.
* This is to ensure backwards compatibility, see:
* https://github.com/jupyter-widgets/ipywidgets/pull/3738/commits/f9e27328bb631eb5247a7a6563595d3e655492c7#diff-efb19099381ae8911dd7f69b015a0138d08da7164512c1ee112aa75100bc9be2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL seems to be broken? Maybe due to a rebase?

ibdafna added a commit that referenced this pull request Sep 12, 2023
Reverts #3689 and #3738 back to the original working codebase
martinRenou added a commit to martinRenou/ipywidgets that referenced this pull request Sep 13, 2023
martinRenou added a commit to martinRenou/ipywidgets that referenced this pull request Sep 13, 2023
martinRenou added a commit to martinRenou/ipywidgets that referenced this pull request Sep 13, 2023
martinRenou added a commit that referenced this pull request Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants