Skip to content

Commit 216552d

Browse files
authored
handle literal subclass (#5081)
1 parent acb0bc2 commit 216552d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

reflex/utils/types.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,18 @@ def typehint_issubclass(
996996
for arg in args
997997
)
998998

999+
if is_literal(possible_subclass):
1000+
args = get_args(possible_subclass)
1001+
return all(
1002+
_isinstance(
1003+
arg,
1004+
possible_superclass,
1005+
treat_mutable_obj_as_immutable=treat_mutable_superclasss_as_immutable,
1006+
nested=2,
1007+
)
1008+
for arg in args
1009+
)
1010+
9991011
# Remove this check when Python 3.10 is the minimum supported version
10001012
if hasattr(types, "UnionType"):
10011013
provided_type_origin = (

tests/units/utils/test_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def test_is_generic_alias(cls: type, expected: bool):
103103
(str, Literal["test", "value", 2, 3], True),
104104
(int, Literal["test", "value"], False),
105105
(int, Literal["test", "value", 2, 3], True),
106+
(Literal["test", "value"], str, True),
107+
(Literal["test", "value", 2, 3], str, False),
108+
(Literal["test", "value"], int, False),
109+
(Literal["test", "value", 2, 3], int, False),
106110
*[
107111
(NoReturn, super_class, True)
108112
for super_class in [int, float, str, bool, list, dict, object, Any]

0 commit comments

Comments
 (0)