Skip to content

Commit 6868b33

Browse files
authored
slicing a list is not a mutable proxy directly (#5221)
1 parent c90b73a commit 6868b33

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

reflex/state.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3937,6 +3937,8 @@ def __getitem__(self, key: Any) -> Any:
39373937
The item value.
39383938
"""
39393939
value = super().__getitem__(key)
3940+
if isinstance(key, slice) and isinstance(value, list):
3941+
return [self._wrap_recursive(item) for item in value]
39403942
# Recursively wrap mutable items retrieved through this proxy.
39413943
return self._wrap_recursive(value)
39423944

tests/units/test_state.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,10 @@ def test_setattr_of_mutable_types(mutable_state: MutableTestState):
15051505
assert isinstance(array[1], list)
15061506
assert isinstance(array[2], MutableProxy)
15071507
assert isinstance(array[2], dict)
1508+
assert isinstance(array[:], list)
1509+
assert not isinstance(array[:], MutableProxy)
1510+
assert isinstance(array[:][1], MutableProxy)
1511+
assert isinstance(array[:][1], list)
15081512

15091513
assert isinstance(hashmap, MutableProxy)
15101514
assert isinstance(hashmap, dict)

0 commit comments

Comments
 (0)