Skip to content
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

Raise AttributeError when attempting to set value on an rx obj #1022

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Feb 14, 2025

Resolves #869

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.26%. Comparing base (aa3315a) to head (ee55f61).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1022      +/-   ##
==========================================
+ Coverage   87.25%   87.26%   +0.01%     
==========================================
  Files           9        9              
  Lines        4928     4932       +4     
==========================================
+ Hits         4300     4304       +4     
  Misses        628      628              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -1961,6 +1961,11 @@ def _eval_operation(self, obj, operation):
obj = fn(obj, *resolved_args, **resolved_kwargs)
return obj

def __setattr__(self, name, value):
if name == "value":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only value?

And what if the underlying object itself has a value attribute?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what if the underlying object itself has a value attribute?

I don't think this has any consequence? Currently, for an object that has a value attribute, rx(obj).value returns a reactive expression. Setting rx(obj).value sets value on the reactive expression, not on the underlying object, which can be done with rx(obj).rx.value = <value>. Let me know if I got this wrong.

Why only value?

Because that's the most error-prone attribute in my opinion and I don't want to restrict __setattr__ too much beyond that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raise an error when setting attributes on a reactive object
2 participants