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

Var: __bool__ and __iter__ always raise a TypeError #1750

Merged
merged 3 commits into from
Sep 5, 2023
Merged

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented Sep 5, 2023

To help avoid programming mistakes when using Var, any attempt to use a Var in a conditional, or with short circuit operators will now raise a TypeError with the exception message suggesting the use of rx.cond, and bitwise operators instead.

Attempting to use a Var with a native for loop or list comprehension will also raise a TypeError suggesting the use of rx.foreach


Fix all test cases that were making erroneous Var assertions

  • must use .equals() to actually compare Var instances
  • must ._decode() Vars to compare with python values
  • must use if x is not None instead of if x where x is a Var

To help avoid programming mistakes when using Var, any attempt to use a Var in
a conditional, or with short circuit operators will now raise a TypeError with
the exception message suggesting the use of `rx.cond`, and bitwise operators
instead.

Attempting to use a Var with a native for loop or list comprehension will also
raise a TypeError suggesting the use of `rx.foreach`

----------------

Fix all test cases that were making erroneous Var assertions
  * must use `.equals()` to actually compare Var instances
  * must `._decode()` Vars to compare with python values
  * must use `if x is not None` instead of `if x` where x is a Var
Truthy-ness of a var cannot be determined at compile time!
In `format_array_ref` check for Var explicitly `is not None`
@masenf masenf changed the title vars.Var: __bool__ and __iter__ always raise a TypeError Var: __bool__ and __iter__ always raise a TypeError Sep 5, 2023
Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

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

Awesome

Raises:
TypeError: when attempting to bool-ify the Var.
"""
raise TypeError(
Copy link
Contributor

Choose a reason for hiding this comment

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

We can also link to the relevant portion of the docs here

@picklelo picklelo merged commit 71811a6 into main Sep 5, 2023
34 checks passed
@picklelo picklelo deleted the masenf/var-bool branch September 5, 2023 20:44
@masenf masenf mentioned this pull request Sep 7, 2023
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