Hi everyone. I would like to send a computed property from python to a speckle 2.0 stream. However, when I use the object below, the value for required_amount is not available on the server. Is there any way to fix this without declaring it in the init?
Sorry for the late reply, your post must have fallen through the cracks…
As for your question, I don’t think this is doable, as the whole point of computed properties is that you don’t need to serialise them (as their value would be recomputed when needed
Pinging @gjedlicska in-case there’s some python black-magic that can be done to get the result you want.
As Alan said, properties in python are not supported for serialization, as the example below shows. We’re following the same in our base class currently.
import json
from dataclasses import dataclass, asdict
@dataclass
class Foo:
bar: str
@property
def also_bar(self):
return self.bar
if __name__ == "__main__":
foo = Foo('asdf')
print(json.dumps(asdict(foo)))