You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm aware this is a toy example and I can do var - something already because of the built in functions. The actual function I'm dealing with does a bit more which is why I want to encapsulate it in one place and reuse throughout the view layer instead of writing it out multiple times.
However the var system is not able to find this compute method, as in when I write rx.text(f"{test.compute(2)") I get reflex.utils.exceptions.VarAttributeError: The State var team of type <class 'schema.Test'> has no attribute 'compute' or may have been annotated wrongly.
And when I try to annotate with @rx.var I get Computed var compute(self, year: int) -> int cannot take arguments.
How exactly do I access this method on the var and use it from within the view layer?
I suppose one workaround is to define these as @staticmethod and then call it as Test.compute(test, 2) but this feels kind of clunky and not how I would expect to use a class normally in python.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I see that Computed Vars cannot take arguments, but I also see that I cannot use any methods on the var to make computations.
Say I have:
I'm aware this is a toy example and I can do
var - something
already because of the built in functions. The actual function I'm dealing with does a bit more which is why I want to encapsulate it in one place and reuse throughout the view layer instead of writing it out multiple times.However the var system is not able to find this compute method, as in when I write
rx.text(f"{test.compute(2)")
I getreflex.utils.exceptions.VarAttributeError: The State var
teamof type <class 'schema.Test'> has no attribute 'compute' or may have been annotated wrongly.
And when I try to annotate with
@rx.var
I getComputed var compute(self, year: int) -> int
cannot take arguments.How exactly do I access this method on the var and use it from within the view layer?
I suppose one workaround is to define these as @staticmethod and then call it as Test.compute(test, 2) but this feels kind of clunky and not how I would expect to use a class normally in python.
Beta Was this translation helpful? Give feedback.
All reactions