Skip to content

Commit

Permalink
fix: Only use path when determining equality of implicit modules (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-koch authored May 15, 2024
1 parent af4fb07 commit 6f47d4b
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions guppylang/decorator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
from collections.abc import Callable
from dataclasses import dataclass
from dataclasses import dataclass, field
from pathlib import Path
from types import ModuleType
from typing import Any, TypeVar
Expand Down Expand Up @@ -35,17 +35,11 @@ class ModuleIdentifier:
"""Identifier for the Python file/module that called the decorator."""

filename: Path
module: ModuleType | None

@property
def name(self) -> str:
"""Returns a user-friendly name for the caller.
If the called is not a function, uses the file name.
"""
if self.module is not None:
return str(self.module.__name__)
return self.filename.name
#: The name of the module. We only store this to have nice name to report back to
#: the user. When determining whether two `ModuleIdentifier`s correspond to the same
#: module, we only take the module path into account.
name: str = field(compare=False)


class _Guppy:
Expand Down Expand Up @@ -102,7 +96,10 @@ def _get_python_caller(self, fn: PyFunc | None = None) -> ModuleIdentifier:
break
else:
raise GuppyError("Could not find a caller for the `@guppy` decorator")
return ModuleIdentifier(Path(filename), module)
module_path = Path(filename)
return ModuleIdentifier(
module_path, module.__name__ if module else module_path.name
)

@pretty_errors
def extend_type(self, module: GuppyModule, defn: TypeDef) -> ClassDecorator:
Expand Down

0 comments on commit 6f47d4b

Please sign in to comment.