-
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
improve object var symantics #4290
Conversation
Hi @adhami3310 thanks! class Bare:
@property
def prop(self) -> int:
return 4
@serializer(to=dict)
def serialize_bare(bare: Bare) -> dict[str, int]:
return {"prop": bare.prop} I would love to see a fallback to ObjectVar (a bit like #3911). At least if there is a serializer which serializes to class IsObjectVar: ...
class Bare(IsObjectVar): ... |
I believe so, I can add an additional check for has_serializer. |
I would suggest limiting this case to serializers which serialize to dict only. class MyCls: ...
@serializer(to=str)
def serialize_my_cls(my_cls: MyCls) -> str:
return "hi" Btw, I still think we can narrow this down to serializers and only use the serializers to determine ObjectVar support (dataclasses and rx.Base also have serializers to dict) This will shrink down the checks, make the code cleaner by removing all those cases and potentially even improve performance |
Should be done!
we should, I will try to do that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @adhami3310 this looks great! I will test it against our code now
Edit: works great!
@benedikt-bartscher made some changes here, let me know if any more is needed