From e9e2b31dc10cb8c5d94c3b71539f995748c94741 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Wed, 20 Aug 2025 16:54:55 -0700 Subject: [PATCH] improve literal handling in pyi generator --- reflex/utils/pyi_generator.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/reflex/utils/pyi_generator.py b/reflex/utils/pyi_generator.py index 4d10e62c3bb..6aa6ac67dee 100644 --- a/reflex/utils/pyi_generator.py +++ b/reflex/utils/pyi_generator.py @@ -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): @@ -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