Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
path: ./dist
- name: Install
run: |
pip install `echo dist/*.whl`[dev] "bqplot<0.13" "pandas<3" "ruff==0.8.3" "ipyvue${{ matrix.ipyvue }}" "ipyvuetify${{ matrix.ipyvue }}"
pip install `echo dist/*.whl`[dev] "bqplot<0.13" six "pandas<3" "ruff==0.8.3" "ipyvue${{ matrix.ipyvue }}" "ipyvuetify${{ matrix.ipyvue }}"
- name: test
env:
REACTON_FAST: ${{ matrix.reacton-fast }}
Expand Down
18 changes: 10 additions & 8 deletions reacton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,10 @@ def _create_widget(self, kwargs):
try:
try:
widget = self.component.widget(**kwargs)
hold_trait_notifications = widget.hold_trait_notifications

@contextlib.contextmanager
def hold_trait_notifications_extra(*args, **kwargs):
with rc, hold_trait_notifications(*args, **kwargs):
yield

widget.hold_trait_notifications = hold_trait_notifications_extra
# A partial of one module-level context manager, not a @contextlib.contextmanager defined here:
# that decorator runs functools.wraps for every widget, and on free-threaded Python setting
# attributes on a function object stops all threads.
widget.hold_trait_notifications = functools.partial(_hold_trait_notifications_extra, rc, widget.hold_trait_notifications)

if self._meta:
widget._react_meta = dict(self._meta)
Expand Down Expand Up @@ -3423,3 +3419,9 @@ def Fragment(children: List[Element]):
# not a public api yet, used in solara for now only.
# lifecycle of context objects are linked to the lifecycle of the component
_component_context_manager_classes: List[Any] = []


@contextlib.contextmanager
def _hold_trait_notifications_extra(rc, hold_trait_notifications, *args, **kwargs):
with rc, hold_trait_notifications(*args, **kwargs):
yield
25 changes: 25 additions & 0 deletions reacton/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4437,3 +4437,28 @@ def Level():
with pytest.raises(ValueError):
rc.close() # close() raises the error of the failed render again
assert time.monotonic() - start < 2


def test_create_widget_does_not_wrap_a_function_per_widget():
# on free-threaded Python, functools.wraps (setting attributes on a function) stops all threads,
# so creating a widget should not define and wrap a new function
import functools

@react.component
def Test():
with w.VBox() as main:
for i in range(10):
w.IntSlider(value=i)
return main

with unittest.mock.patch("functools.update_wrapper", wraps=functools.update_wrapper) as update_wrapper:
box, rc = react.render(Test(), handle_error=False)
assert update_wrapper.call_count == 0
slider = rc.find(widgets.IntSlider).widgets[0]
changes = []
slider.observe(lambda change: changes.append(change["new"]), "value")
with slider.hold_trait_notifications():
slider.value = 42
assert changes == []
assert changes == [42]
rc.close()
Loading