Skip to content

Commit

Permalink
refactor ImportsAnalyzer not not use id()
Browse files Browse the repository at this point in the history
since we no longer need to worry about __hash__ and __eq__performance
  • Loading branch information
charles-cooper committed Jan 1, 2025
1 parent 71726ad commit d8b2f58
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions vyper/semantics/analysis/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def push_path(self, module_ast: vy_ast.Module) -> None:

def pop_path(self, expected: vy_ast.Module) -> None:
popped = self._path.pop()
if expected is not popped: # FIXME - use expected != popped
raise CompilerPanic("unreachable")
assert expected is popped, "unreachable"
self._imports.pop()

@contextlib.contextmanager
Expand All @@ -77,7 +76,7 @@ def __init__(self, input_bundle: InputBundle, graph: _ImportGraph):
self.graph = graph
self._ast_of: dict[int, vy_ast.Module] = {}

self.seen: set[int] = set()
self.seen: set[vy_ast.Module] = set()

self.integrity_sum = None

Expand All @@ -102,15 +101,15 @@ def _calculate_integrity_sum_r(self, module_ast: vy_ast.Module):
return sha256sum("".join(acc))

def _resolve_imports_r(self, module_ast: vy_ast.Module):
if id(module_ast) in self.seen:
if module_ast in self.seen:
return
with self.graph.enter_path(module_ast):
for node in module_ast.body:
if isinstance(node, vy_ast.Import):
self._handle_Import(node)
elif isinstance(node, vy_ast.ImportFrom):
self._handle_ImportFrom(node)
self.seen.add(id(module_ast))
self.seen.add(module_ast)

def _handle_Import(self, node: vy_ast.Import):
# import x.y[name] as y[alias]
Expand Down

0 comments on commit d8b2f58

Please sign in to comment.