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

add immutable var class #3607

Merged
merged 9 commits into from
Jul 3, 2024
Merged

add immutable var class #3607

merged 9 commits into from
Jul 3, 2024

Conversation

adhami3310
Copy link
Contributor

The ImmutableVar is a dataclass that inherits from Var, very similar to the current BaseVar, except without any setter or default value logic and with frozen=True so that it is immutable.

masenf
masenf previously requested changes Jul 2, 2024
Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

needs an overridden _replace method that returns ImmutableVar instances.

it actually might make sense to override create as well to something like this

@classmethod
def create(self, ...):
    return super().create(...)._replace()

That way we can create ImmutableVar instances in the same way as Var instances until more special-case behavior is added.

reflex/experimental/vars/base.py Outdated Show resolved Hide resolved
@adhami3310 adhami3310 requested a review from masenf July 2, 2024 19:07
@adhami3310 adhami3310 dismissed masenf’s stale review July 2, 2024 19:25

override create in last commit

reflex/experimental/vars/base.py Outdated Show resolved Hide resolved
@adhami3310 adhami3310 requested a review from masenf July 2, 2024 21:07
reflex/experimental/vars/base.py Outdated Show resolved Hide resolved
reflex/experimental/vars/base.py Outdated Show resolved Hide resolved
reflex/experimental/vars/base.py Outdated Show resolved Hide resolved
@adhami3310 adhami3310 requested a review from masenf July 2, 2024 22:43
Lendemor
Lendemor previously approved these changes Jul 3, 2024
masenf
masenf previously requested changes Jul 3, 2024
Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

we can hold off on adding tests for now, because most of the API for ImmutableVar is coming from Var itself and won't represent the final usage of the API.

but in a near-future PR, we will want to make sure these changes are coming in with near-full test coverage, because it's much easier to add tests incrementally, rather than at the end.

reflex/experimental/__init__.py Show resolved Hide resolved
reflex/experimental/vars/__init__.py Show resolved Hide resolved
@masenf masenf merged commit 046c0f9 into main Jul 3, 2024
47 checks passed
@adhami3310 adhami3310 deleted the immutable-var branch July 3, 2024 18:23
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.

None yet

3 participants