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

Negate var using not #1736

Closed
arnomoonens opened this issue Sep 1, 2023 · 3 comments
Closed

Negate var using not #1736

arnomoonens opened this issue Sep 1, 2023 · 3 comments
Labels
wontfix This will not be worked on

Comments

@arnomoonens
Copy link
Contributor

Describe the bug
Negating a var using not v does not work.

To Reproduce
For example, creating a var in State is_false: bool = False and then using rx.cond(not State.is_false, rx.text("negated"), rx.text("not negated")). It always shows the text not negated.

Expected behavior
I expected the var to be correctly negated.

Specifics:

  • Python Version: 3.11.5
  • Reflex Version: 0.2.6
  • OS: macOS 13.5.1 (22G90)
  • Browser (Optional): Arc; version 1.6.0 (41215)

Additional context
It works using ~State.is_false but it would me more user-friendly if it works using not.

@Lendemor Lendemor added the wontfix This will not be worked on label Sep 6, 2023
@Lendemor
Copy link
Collaborator

Lendemor commented Sep 6, 2023

According to what @pickelo said, Python will not let us override the not so we can't do anything about that.
Quote from our Discord :

The not, and, and or operators are unfortunately not able to be overriden in Python. To use with vars, we have the equivalents which are ~, &, and |

@picklelo
Copy link
Contributor

picklelo commented Sep 6, 2023

To negate the var, you can use the ~ operator:

rx.cond(~State.is_false, rx.text("negated"), rx.text("not negated"))

@masenf
Copy link
Collaborator

masenf commented Sep 7, 2023

Yeah unfortunately we will have to close this, since it's not currently possible without AST manipulation, which we're not getting into at this point.

I implemented #1750 which will raise a TypeError when trying to use a Var with if, and, or or not and suggest the use of our alternative operations. That will have to be enough for now.

@masenf masenf closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants