Skip to content

Commit 0b34566

Browse files
committed
Unify _get_visible_type_name between type_to_ast and _get_type_hint
Include plain names that are present in the DEFAULT_IMPORTS
1 parent 319e4eb commit 0b34566

File tree

2 files changed

+112
-116
lines changed

2 files changed

+112
-116
lines changed

packages/reflex-base/src/reflex_base/utils/pyi_generator.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,12 @@ def _get_visible_type_name(
627627
if type_hint_globals is None:
628628
return None
629629

630+
type_module = getattr(typ, "__module__", None)
630631
type_name = getattr(typ, "__name__", None)
631-
if (
632-
type_name is not None
633-
and type_name in type_hint_globals
634-
and type_hint_globals[type_name] is typ
632+
633+
if type_name is not None and (
634+
type_hint_globals.get(type_name) is typ
635+
or type_name in DEFAULT_IMPORTS.get(str(type_module), set())
635636
):
636637
return type_name
637638

@@ -686,11 +687,6 @@ def type_to_ast(
686687
return ast.Name(id=typ.__name__)
687688
if visible_name := _get_visible_type_name(typ, type_hint_globals):
688689
return ast.Name(id=visible_name)
689-
if (
690-
typ.__module__ in DEFAULT_IMPORTS
691-
and typ.__name__ in DEFAULT_IMPORTS[typ.__module__]
692-
):
693-
return ast.Name(id=typ.__name__)
694690
return ast.Name(id=typ.__module__ + "." + typ.__name__)
695691
return ast.Name(id=typ.__name__)
696692
if hasattr(typ, "_name"):

0 commit comments

Comments
 (0)