Skip to content

Type errors when using rx.cond on a "Literal" argument #6538

@luator

Description

@luator

Describe the bug
Not sure if this is really a bug, maybe rather a feature request, but since it wasn't a problem in previous versions, I'm considering it a bug for now

After a recent update, we get lots of pyright complains when assigning the return value of rx.cond to an argument that expects a literal value (e.g. color_scheme).

To Reproduce

 rx.callout(
    ...
    color_scheme=rx.cond(
        State.condition, "green", "red"
    ),
),

Running pyright gives the following error:

Argument of type "Var[str]" cannot be assigned to parameter "color_scheme" of type "Var[Literal['amber', 'blue', 'bronze', 'brown', 'crimson', 'cyan', 'gold', 'grass', 'gray', 'green', 'indigo', 'iris', 'jade', 'lime', 'mint', 'orange', 'pink', 'plum', 'purple', 'red', 'ruby', 'sky', 'teal', 'tomato', 'violet', 'yellow']] | Literal['amber', 'blue', 'bronze', 'brown', 'crimson', 'cyan', 'gold', 'grass', 'gray', 'green', 'indigo', 'iris', 'jade', 'lime', 'mint', 'orange', 'pink', 'plum', 'purple', 'red', 'ruby', 'sky', 'teal', 'tomato', 'violet', 'yellow'] | None" in function "call"
  Type "Var[str]" is not assignable to type "Var[Literal['amber', 'blue', 'bronze', 'brown', 'crimson', 'cyan', 'gold', 'grass', 'gray', 'green', 'indigo', 'iris', 'jade', 'lime', 'mint', 'orange', 'pink', 'plum', 'purple', 'red', 'ruby', 'sky', 'teal', 'tomato', 'violet', 'yellow']] | Literal['amber', 'blue', 'bronze', 'brown', 'crimson', 'cyan', 'gold', 'grass', 'gray', 'green', 'indigo', 'iris', 'jade', 'lime', 'mint', 'orange', 'pink', 'plum', 'purple', 'red', 'ruby', 'sky', 'teal', 'tomato', 'violet', 'yellow'] | None"
    "Var[str]" is not assignable to "Var[Literal['amber', 'blue', 'bronze', 'brown', 'crimson', 'cyan', 'gold', 'grass', 'gray', 'green', 'indigo', 'iris', 'jade', 'lime', 'mint', 'orange', 'pink', 'plum', 'purple', 'red', 'ruby', 'sky', 'teal', 'tomato', 'violet', 'yellow']]"
      Type parameter "VAR_TYPE@Var" is covariant, but "str" is not a subtype of "Literal['amber', 'blue', 'bronze', 'brown', 'crimson', 'cyan', 'gold', 'grass', 'gray', 'green', 'indigo', 'iris', 'jade', 'lime', 'mint', 'orange', 'pink', 'plum', 'purple', 'red', 'ruby', 'sky', 'teal', 'tomato', 'violet', 'yellow']"
        Type "str" is not assignable to type "Literal['amber', 'blue', 'bronze', 'brown', 'crimson', 'cyan', 'gold', 'grass', 'gray', 'green', 'indigo', 'iris', 'jade', 'lime', 'mint', 'orange', 'pink', 'plum', 'purple', 'red', 'ruby', 'sky', 'teal', 'tomato', 'violet', 'yellow']"
          "str" is not assignable to type "Literal['amber']"
          "str" is not assignable to type "Literal['blue']"
          "str" is not assignable to type "Literal['bronze']"
          "str" is not assignable to type "Literal['brown']"
... (reportArgumentType)

Expected behavior
Since both "red" and "green" are in the list of literals, I'd expect this type check to pass.
Not sure if this can easily be achieved in Python but at least in previous versions, this was not an issue.

Specifics (please complete the following information):

  • Python Version: 3.14
  • Reflex Version: 0.9.2.post1
  • OS: Kubuntu 24.04
  • pyright Version: 1.1.409

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions