1
0
Khaleel Al-Adhami 1 сар өмнө
parent
commit
216552df62

+ 12 - 0
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 = (

+ 4 - 0
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]