Skip to content

Commit e555de6

Browse files
committed
greptile feedback
* better visit_Import handling to avoid duplicate imports and missing default imports * add is_reflex_package escape hatch to second condition in _rewrite_component_import
1 parent 98ac5b7 commit e555de6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,19 +1088,19 @@ def visit_Import(
10881088
Returns:
10891089
The modified import node(s).
10901090
"""
1091-
if not self.inserted_imports:
1092-
self.inserted_imports = True
1093-
default_imports = _generate_imports(self.typing_imports)
1094-
return [*default_imports, node]
10951091
# Drop any imports in the EXCLUDED_IMPORTS mapping since they are supplied by DEFAULT_IMPORTS.
10961092
if isinstance(node, ast.ImportFrom) and node.module in EXCLUDED_IMPORTS:
10971093
node.names = [
10981094
alias
10991095
for alias in node.names
11001096
if alias.name not in EXCLUDED_IMPORTS[node.module]
11011097
]
1102-
if not node.names:
1103-
return []
1098+
if not self.inserted_imports:
1099+
self.inserted_imports = True
1100+
default_imports = _generate_imports(self.typing_imports)
1101+
return [*default_imports, *([node] if node.names else ())]
1102+
if not node.names:
1103+
return []
11041104
return node
11051105

11061106
def visit_ImportFrom(
@@ -1368,7 +1368,7 @@ def _rewrite_component_import(module: str, is_reflex_package: bool) -> str:
13681368
# "components": ["el", "radix", ...] — these are re-exported submodules.
13691369
# Can't map to a single package, but the pyi generator handles each attr individually.
13701370
return "reflex_components_core"
1371-
if module.startswith("components."):
1371+
if is_reflex_package and module.startswith("components."):
13721372
rest = module[len("components.") :]
13731373
# Try progressively deeper matches (e.g. "datadisplay.code" before "datadisplay").
13741374
parts = rest.split(".")

0 commit comments

Comments
 (0)