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

[REF-3328] Implement __getitem__ for ArrayVar #3705

Merged
merged 26 commits into from
Jul 30, 2024

Conversation

adhami3310
Copy link
Member

No description provided.

Copy link

linear bot commented Jul 25, 2024

@adhami3310 adhami3310 requested a review from masenf July 25, 2024 18:45
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.

i still need to do more testing, but it doesn't look like the _var_type is properly passed for the keys, values and entries operations

reflex/experimental/vars/object.py Outdated Show resolved Hide resolved
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.

partway through the new stuff

reflex/experimental/vars/object.py Outdated Show resolved Hide resolved
reflex/experimental/vars/object.py Outdated Show resolved Hide resolved
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.

the following code needs to work if the annotation is there

>>> ov2 = rx._x.vars.LiteralVar.create({"foo": "bar"})
>>> ov2["foo"].upper()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/masen/code/reflex-dev/reflex/reflex/vars.py", line 1726, in upper
    return self._replace(
           ^^^^^^^^^^^^^^
  File "/Users/masen/code/reflex-dev/reflex/reflex/experimental/vars/base.py", line 160, in _replace
    return type(self)(**field_values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ObjectItemOperation.__init__() got an unexpected keyword argument '_var_name'

This seems to be hitting upper in the base Var, because the resulting ObjectItemOperation isn't a StringVar.

Similar but different, if we cast the value to dict[str, str], then it still doesn't really work

>>> ov = rx._x.vars.LiteralVar.create({"foo": "bar"}).to(rx._x.vars.ObjectVar, dict[str,str])
Warning: `rx._x` contains experimental features and might be removed at any time in the future .
>>> ov["foo"].lower()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/masen/code/reflex-dev/reflex/reflex/vars.py", line 1702, in lower
    raise VarTypeError(
reflex.utils.exceptions.VarTypeError: Cannot convert non-string var ({ ["foo"] : "bar" })["foo"] to lowercase.
>>> ov["foo"]
ObjectItemOperation(_var_name='({ ["foo"] : "bar" })["foo"]', _var_type=<class 'reflex.experimental.vars.base.ImmutableVar'>, _var_data=None, value=ToObjectOperation(_var_name='({ ["foo"] : "bar" })', _var_type=dict[str, str], _var_data=None, _original_var=LiteralObjectVar(_var_name='({ ["foo"] : "bar" })', _var_type=typing.Dict[str, str], _var_data=None, _var_value={'foo': 'bar'})), key=LiteralStringVar(_var_name='"foo"', _var_type=<class 'str'>, _var_data=None, _var_value='foo'))

in this case, the resulting ObjectItemOperation gets _var_type=ImmutableVar which doesn't seem quite right.

It seems like these item accessing operations probably need to also use .to in order to correctly cast the resulting value based on the annotation in the original var.

we also need test cases for these chain operations

@@ -1232,6 +1278,20 @@ def unionize(*args: Type) -> Type:
return Union[first, unionize(*rest)]


def is_tuple_type(t: GenericType) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think rx.utils.types._issubclass implements this already

@@ -433,6 +473,16 @@ def create(
def __post_init__(self):
"""Post-initialize the var."""

def json(self) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the json() method intended to be used for?

@adhami3310 adhami3310 merged commit 1c40004 into main Jul 30, 2024
47 checks passed
cutoffthetop referenced this pull request in robert-koch-institut/mex-editor Aug 8, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [reflex](https://reflex.dev)
([source](https://togithub.com/reflex-dev/reflex)) |
project.dependencies | patch | `==0.5.8` -> `==0.5.9` |

---

### Release Notes

<details>
<summary>reflex-dev/reflex (reflex)</summary>

###
[`v0.5.9`](https://togithub.com/reflex-dev/reflex/releases/tag/v0.5.9)

[Compare
Source](https://togithub.com/reflex-dev/reflex/compare/v0.5.8...v0.5.9)

#### Bug Fixes

- fix silly bug when style is set directly to breakpoints by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3719](https://togithub.com/reflex-dev/reflex/pull/3719)
- Fix event actions like `stop_propagation` for recharts event triggers
- \[REF-3203] Find a DOM event-like object in addEvents by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3706](https://togithub.com/reflex-dev/reflex/pull/3706)
- fix initial_value for computed_var by
[@&#8203;benedikt-bartscher](https://togithub.com/benedikt-bartscher) in
[https://github.com/reflex-dev/reflex/pull/3726](https://togithub.com/reflex-dev/reflex/pull/3726)
- add test for initial state dict by
[@&#8203;benedikt-bartscher](https://togithub.com/benedikt-bartscher) in
[https://github.com/reflex-dev/reflex/pull/3727](https://togithub.com/reflex-dev/reflex/pull/3727)
- Improve Client-Side Routing on Page Not Found by
[@&#8203;Manas1820](https://togithub.com/Manas1820) in
[https://github.com/reflex-dev/reflex/pull/3723](https://togithub.com/reflex-dev/reflex/pull/3723)
- Use the new state name when setting `is_hydrated` to false by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3738](https://togithub.com/reflex-dev/reflex/pull/3738)
- Use `._is_mutable()` to account for parent state proxy by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3739](https://togithub.com/reflex-dev/reflex/pull/3739)

#### Doc Updates

- Add comments to html by [@&#8203;Alek99](https://togithub.com/Alek99)
in
[https://github.com/reflex-dev/reflex/pull/3731](https://togithub.com/reflex-dev/reflex/pull/3731)

#### Var Refactor

This release includes some new experimental features being developed
incrementally in reflex.\_x.vars.

- \[REF-3328] Implement **getitem** for ArrayVar by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3705](https://togithub.com/reflex-dev/reflex/pull/3705)
- add type hinting to existing types by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3729](https://togithub.com/reflex-dev/reflex/pull/3729)

**Full Changelog**:
reflex-dev/reflex@v0.5.8...v0.5.9

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xOC4xNyIsInVwZGF0ZWRJblZlciI6IjM4LjIzLjAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbXX0=-->
cutoffthetop referenced this pull request in robert-koch-institut/mex-drop Aug 20, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [reflex](https://reflex.dev)
([source](https://togithub.com/reflex-dev/reflex)) |
project.dependencies | patch | `==0.5.8` -> `==0.5.9` |

---

### Release Notes

<details>
<summary>reflex-dev/reflex (reflex)</summary>

###
[`v0.5.9`](https://togithub.com/reflex-dev/reflex/releases/tag/v0.5.9)

[Compare
Source](https://togithub.com/reflex-dev/reflex/compare/v0.5.8...v0.5.9)

#### Bug Fixes

- fix silly bug when style is set directly to breakpoints by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3719](https://togithub.com/reflex-dev/reflex/pull/3719)
- Fix event actions like `stop_propagation` for recharts event triggers
- \[REF-3203] Find a DOM event-like object in addEvents by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3706](https://togithub.com/reflex-dev/reflex/pull/3706)
- fix initial_value for computed_var by
[@&#8203;benedikt-bartscher](https://togithub.com/benedikt-bartscher) in
[https://github.com/reflex-dev/reflex/pull/3726](https://togithub.com/reflex-dev/reflex/pull/3726)
- add test for initial state dict by
[@&#8203;benedikt-bartscher](https://togithub.com/benedikt-bartscher) in
[https://github.com/reflex-dev/reflex/pull/3727](https://togithub.com/reflex-dev/reflex/pull/3727)
- Improve Client-Side Routing on Page Not Found by
[@&#8203;Manas1820](https://togithub.com/Manas1820) in
[https://github.com/reflex-dev/reflex/pull/3723](https://togithub.com/reflex-dev/reflex/pull/3723)
- Use the new state name when setting `is_hydrated` to false by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3738](https://togithub.com/reflex-dev/reflex/pull/3738)
- Use `._is_mutable()` to account for parent state proxy by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3739](https://togithub.com/reflex-dev/reflex/pull/3739)

#### Doc Updates

- Add comments to html by [@&#8203;Alek99](https://togithub.com/Alek99)
in
[https://github.com/reflex-dev/reflex/pull/3731](https://togithub.com/reflex-dev/reflex/pull/3731)

#### Var Refactor

This release includes some new experimental features being developed
incrementally in reflex.\_x.vars.

- \[REF-3328] Implement **getitem** for ArrayVar by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3705](https://togithub.com/reflex-dev/reflex/pull/3705)
- add type hinting to existing types by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3729](https://togithub.com/reflex-dev/reflex/pull/3729)

**Full Changelog**:
reflex-dev/reflex@v0.5.8...v0.5.9

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC40NC4wIiwidXBkYXRlZEluVmVyIjoiMzguNDQuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
@masenf masenf deleted the khaleel/ref-3328-implement-__getitem__-for-arrayvar branch December 12, 2024 07:10
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.

2 participants