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

rx.match doesn't work within f-string #3213

Open
TimChild opened this issue May 2, 2024 · 1 comment
Open

rx.match doesn't work within f-string #3213

TimChild opened this issue May 2, 2024 · 1 comment
Labels
bug Something isn't working linear Created by Linear-GitHub Sync

Comments

@TimChild
Copy link

TimChild commented May 2, 2024

Describe the bug
Trying to use an rx.match within an f-string causes a failed to compile error that shows up in the browser, but no sign of issues during compiling.

To Reproduce
Steps to reproduce the behavior:

import reflex as rx


@rx.page('/')
def index():
    return rx.text(f'Error with match as part of fstring: {rx.match("a", ("a", "Matched a"), "b")}')
    # return rx.text(f'No error if outside fstring: ', rx.match("a", ("a", "Matched a"), "b"))

Adding .to(str) or .to_string() to the rx.match also results in the same error in case that is relevant.

The easy alternative is to just separate the rx.match from the string, but this is only easy once you figure out what the problem is in the first place....

Expected behavior
Given that other rx.Vars can be used within an f-string, and that rx.match can often be used where an rx.Var would be used (e.g. setting prop values) I would have expected rx.match to also work within an f-string.

Took me quite a while to realise what the error message was telling me because the point of error appears to be within the rx.match component, but of course the real issue is that the whole thing is sort of being treated as a string.

I don't think this necessarily needs to be supported, but would be nice to get a more helpful error :)

Screenshots
image

Specifics (please complete the following information):

  • Python Version: 3.11
  • Reflex Version: 4.9
  • OS: WSL2
  • Browser (Optional): Chrome
@Alek99 Alek99 added the bug Something isn't working label May 2, 2024
@ElijahAhianyo ElijahAhianyo added the linear Created by Linear-GitHub Sync label May 13, 2024
@ElijahAhianyo
Copy link
Collaborator

Same for rx.cond as well:

import reflex as rx


@rx.page('/')
def index():
    return rx.text(f'Error with match as part of fstring: {rx.cond(True, "value1", "value2")}')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linear Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

3 participants