Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions nominal_refactor_advisor/ast_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,15 @@ def syntax_index(self) -> ModuleSyntaxIndex:

return ModuleSyntaxIndex.build(self.module)

@cached_property
def has_star_import(self) -> bool:
"""Whether this module contains any `from ... import *` statement, computed once."""

return any(
isinstance(statement, ast.ImportFrom) and any(alias.name == "*" for alias in statement.names)
for statement in ast.walk(self.module)
)

@cached_property
def _facts(self) -> dict[type[ParsedModuleFact], ParsedModuleFact]:
return {}
Expand Down
5 changes: 1 addition & 4 deletions nominal_refactor_advisor/binding_proofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,7 @@ def parse_excludes_star_imports(self, module: ParsedModule, name: str) -> bool:

if self.contains_module(module.module_name):
return self.star_imports_exclude(module.module_name, name)
return not any(
isinstance(statement, ast.ImportFrom) and any(alias.name == "*" for alias in statement.names)
for statement in ast.walk(module.module)
)
return not module.has_star_import

def unshadowed_builtin_witness(
self,
Expand Down
7 changes: 6 additions & 1 deletion nominal_refactor_advisor/class_creation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
FunctionNode: TypeAlias = ast.FunctionDef | ast.AsyncFunctionDef

MODELLED_METACLASSES = frozenset(
("builtins.type", "abc.ABCMeta", "metaclass_registry.core.AutoRegisterMeta")
(
"builtins.type",
"abc.ABCMeta",
"metaclass_registry.abstract_hooks.AbstractHooksMeta",
"metaclass_registry.core.AutoRegisterMeta",
)
)
"""Metaclasses whose class creation NRA knows without reading it: they keep the
bases they are handed and bind only registry names (`MODELLED_BINDINGS`)."""
Expand Down
Loading
Loading