Repository: reflex-dev/reflex

Issue:
Cannot pass a Var of type Literal (with all str values) to a prop annotated as `rx.Var[str]`
**Describe the bug**
It's okay to pass a `Var[str]` when the prop is annotated as `Literal`. But apparently it's not okay to pass a `Var[Literal["x", "y"]]` when the prop is annotated as `str`, even though strictly speaking that is more likely to be correct.

**To Reproduce**
```python
from typing import Literal

import reflex as rx


StatusType = Literal["todo", "doing", "done"]


class MyComponent(rx.Fragment):
    foo: rx.Var[str]


class Item(rx.Base):
    status: StatusType = "todo"


class State(rx.State):
    last_item: Item = Item()


def index() -> rx.Component:
    static_status: StatusType = "done"
    return rx.vstack(
        # Not working
        MyComponent.create(foo=rx.Var.create(Item()).status),
        MyComponent.create(foo=State.last_item.status),
        MyComponent.create(foo=rx.Var("'doing'", _var_type=StatusType)),
        MyComponent.create(foo=rx.Var("'doing'", _var_type=StatusType).guess_type()),
        # Works
        MyComponent.create(foo=rx.Var.create(Item().status)),
        MyComponent.create(foo=static_status),
    )


app = rx.App()
app.add_page(index)
```

**Expected behavior**
All of the cases in the repro app should work.

**Specifics (please complete the following information):**

- Python Version: 3.13
- Reflex Version: 0.7.6dev



Discussion:
<p><a href="https://linear.app/reflex-dev/issue/ENG-5367/cannot-pass-a-var-of-type-literal-with-all-str-values-to-a-prop">ENG-5367 Cannot pass a Var of type Literal (with all str values) to a prop annotated as `rx.Var[str]`</a></p>



Patch:
diff --git a/reflex/utils/types.py b/reflex/utils/types.py
index be8804e085..b88bb216e7 100644
--- a/reflex/utils/types.py
+++ b/reflex/utils/types.py
@@ -996,6 +996,18 @@ def typehint_issubclass(
             for arg in args
         )
 
+    if is_literal(possible_subclass):
+        args = get_args(possible_subclass)
+        return all(
+            _isinstance(
+                arg,
+                possible_superclass,
+                treat_mutable_obj_as_immutable=treat_mutable_superclasss_as_immutable,
+                nested=2,
+            )
+            for arg in args
+        )
+
     # Remove this check when Python 3.10 is the minimum supported version
     if hasattr(types, "UnionType"):
         provided_type_origin = (


Test patch:
diff --git a/tests/units/utils/test_utils.py b/tests/units/utils/test_utils.py
index 8128d69840..751906d4df 100644
--- a/tests/units/utils/test_utils.py
+++ b/tests/units/utils/test_utils.py
@@ -103,6 +103,10 @@ def test_is_generic_alias(cls: type, expected: bool):
         (str, Literal["test", "value", 2, 3], True),
         (int, Literal["test", "value"], False),
         (int, Literal["test", "value", 2, 3], True),
+        (Literal["test", "value"], str, True),
+        (Literal["test", "value", 2, 3], str, False),
+        (Literal["test", "value"], int, False),
+        (Literal["test", "value", 2, 3], int, False),
         *[
             (NoReturn, super_class, True)
             for super_class in [int, float, str, bool, list, dict, object, Any]