Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions reflex/utils/pyi_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _get_type_hint(
res = ""
args = get_args(value)

if value is type(None):
if value is type(None) or value is None:
return "None"

if rx_types.is_union(value):
Expand Down Expand Up @@ -425,10 +425,18 @@ def type_to_ast(typ: Any, cls: type) -> ast.expr:
Returns:
The AST representation of the type annotation.
"""
if typ is type(None):
if typ is type(None) or typ is None:
return ast.Name(id="None")

origin = get_origin(typ)
if origin is typing.Literal:
return ast.Subscript(
value=ast.Name(id="Literal"),
slice=ast.Tuple(
elts=[ast.Constant(value=val) for val in get_args(typ)], ctx=ast.Load()
),
ctx=ast.Load(),
)
if origin is UnionType:
origin = typing.Union

Expand Down
Loading