Skip to content

Commit bc99f35

Browse files
authored
improve literal handling in pyi generator (#5725)
1 parent a5d9a71 commit bc99f35

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

reflex/utils/pyi_generator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _get_type_hint(
145145
res = ""
146146
args = get_args(value)
147147

148-
if value is type(None):
148+
if value is type(None) or value is None:
149149
return "None"
150150

151151
if rx_types.is_union(value):
@@ -425,10 +425,18 @@ def type_to_ast(typ: Any, cls: type) -> ast.expr:
425425
Returns:
426426
The AST representation of the type annotation.
427427
"""
428-
if typ is type(None):
428+
if typ is type(None) or typ is None:
429429
return ast.Name(id="None")
430430

431431
origin = get_origin(typ)
432+
if origin is typing.Literal:
433+
return ast.Subscript(
434+
value=ast.Name(id="Literal"),
435+
slice=ast.Tuple(
436+
elts=[ast.Constant(value=val) for val in get_args(typ)], ctx=ast.Load()
437+
),
438+
ctx=ast.Load(),
439+
)
432440
if origin is UnionType:
433441
origin = typing.Union
434442

0 commit comments

Comments
 (0)