Skip to content

Commit

Permalink
chore: Small error print improvements (#479)
Browse files Browse the repository at this point in the history
Implement `__str__` for `DefId`, so it's easier to see the module name

before:
```py
DefId(id=298, module=<guppylang.module.GuppyModule object at 0x109e18110>)
```
after:
```py
DefId(298, quantum)
```

drive-by: Update uv.lock with the latest release version
  • Loading branch information
aborgna-q authored Sep 12, 2024
1 parent 5cfcdf5 commit 36c76e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions guppylang/definition/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class DefId:
def fresh(cls, module: "GuppyModule | None" = None) -> "DefId":
return DefId(next(cls._ids), module)

def __str__(self) -> str:
if self.module is None:
return f"DefId({self.id}, None)"
return f"DefId({self.id}, {self.module.name})"


@dataclass(frozen=True)
class Definition(ABC):
Expand Down
2 changes: 1 addition & 1 deletion guppylang/tys/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _try_parse_defn(node: AstNode, globals: Globals) -> Definition | None:
match node:
case ast.Name(id=x):
if x not in globals:
raise GuppyError("Unknown identifier", node)
raise GuppyError(f"Unknown identifier `{x}`", node)
return globals[x]
case ast.Attribute(value=ast.Name(id=module_name) as value, attr=x):
if module_name not in globals:
Expand Down

0 comments on commit 36c76e0

Please sign in to comment.