-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rx.foreach Union support #1814
Comments
This line is problematic because The code that comprises the frontend is compiled into javascript code that runs in the browser, so any python conditions and type differentiation must be workable at compile time, not runtime. All runtime logic that needs to be in python must be in event handlers and computed vars in the state. Going back to your original request though, I think it wouldn't be too hard to support union types in the foreach, but you would need your own way of differentiating the types post-serialization if you want to work with them on the frontend. Consider a base class with Until union support is added, you might try to define a |
I think I understood the runtime vs frontend part, thank you. Ok that's more or less the solution I've ended up at, making a class with a label that identifies the type. Thank you for considering adding union support! |
Fix #1814 * Remove py3.7 workarounds, use get_args and get_origin directly * Move `can_access_attribute` to types and call recursively for union types * Extend `is_valid_var_type` to allow Union where all args are valid var types
In my app I'm trying to use an union to hold slightly different classes (common base members but extra members) and using rx.foreach to try to display those entities. If I specify the union, the foreach component won't run, citing :
AttributeError: The State var `_` has no attribute 'MY_ATTRIBUTE' or may have been annotated wrongly.
I've tried to simply make these classes inherit from a single class but I of course cannot access the other members not from the class.
Could I request support for unions for rx.foreach? Would it be hard to implement?
Edit: One option would be to provide a way of specifying a render_fn per type and a default one?
My example setup:
The text was updated successfully, but these errors were encountered: