Skip to content

Commit

Permalink
feat: Utility methods to check if a module contains a fn/type
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Jan 11, 2024
1 parent e17ac31 commit a70470d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion guppy/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,20 @@ def compile(self) -> Hugr | None:
self._compiled = True
return graph

def contains_function(self, name: str) -> bool:
"""Returns 'True' if the module contains a function with the given name."""
return name in self._func_defs or name in self._custom_funcs

def contains_type(self, name: str) -> bool:
"""Returns 'True' if the module contains a type with the given name."""
return name in self._globals.types or name in self._globals.type_vars

def _check_not_yet_compiled(self) -> None:
if self._compiled:
raise GuppyError(f"The module `{self.name}` has already been compiled")

def _check_name_available(self, name: str, node: AstNode | None) -> None:
if name in self._func_defs or name in self._custom_funcs:
if self.contains_function(name):
raise GuppyError(
f"Module `{self.name}` already contains a function named `{name}`",
node,
Expand Down

0 comments on commit a70470d

Please sign in to comment.