fix var dependency over properties (#3588)
This commit is contained in:
parent
33d7ec1f04
commit
a6bdaf1bbe
@ -2174,8 +2174,21 @@ class ComputedVar(Var, property):
|
||||
obj=ref_obj,
|
||||
)
|
||||
)
|
||||
else:
|
||||
# normal attribute access
|
||||
# recurse into property fget functions
|
||||
elif isinstance(ref_obj, property) and not isinstance(
|
||||
ref_obj, ComputedVar
|
||||
):
|
||||
d.update(
|
||||
self._deps(
|
||||
objclass=objclass,
|
||||
obj=ref_obj.fget, # type: ignore
|
||||
)
|
||||
)
|
||||
elif (
|
||||
instruction.argval in objclass.backend_vars
|
||||
or instruction.argval in objclass.vars
|
||||
):
|
||||
# var access
|
||||
d.add(instruction.argval)
|
||||
elif instruction.opname == "LOAD_CONST" and isinstance(
|
||||
instruction.argval, CodeType
|
||||
|
@ -1278,6 +1278,10 @@ def test_computed_var_dependencies():
|
||||
y: List[int] = [1, 2, 3]
|
||||
_z: List[int] = [1, 2, 3]
|
||||
|
||||
@property
|
||||
def testprop(self) -> int:
|
||||
return self.v
|
||||
|
||||
@rx.var(cache=True)
|
||||
def comp_v(self) -> int:
|
||||
"""Direct access.
|
||||
@ -1287,6 +1291,15 @@ def test_computed_var_dependencies():
|
||||
"""
|
||||
return self.v
|
||||
|
||||
@rx.var(cache=True)
|
||||
def comp_v_via_property(self) -> int:
|
||||
"""Access v via property.
|
||||
|
||||
Returns:
|
||||
The value of v via property.
|
||||
"""
|
||||
return self.testprop
|
||||
|
||||
@rx.var(cache=True)
|
||||
def comp_w(self):
|
||||
"""Nested lambda.
|
||||
@ -1328,7 +1341,7 @@ def test_computed_var_dependencies():
|
||||
return [z in self._z for z in range(5)]
|
||||
|
||||
cs = ComputedState()
|
||||
assert cs._computed_var_dependencies["v"] == {"comp_v"}
|
||||
assert cs._computed_var_dependencies["v"] == {"comp_v", "comp_v_via_property"}
|
||||
assert cs._computed_var_dependencies["w"] == {"comp_w"}
|
||||
assert cs._computed_var_dependencies["x"] == {"comp_x"}
|
||||
assert cs._computed_var_dependencies["y"] == {"comp_y"}
|
||||
|
Loading…
Reference in New Issue
Block a user