diff --git a/alfred/domain/shared/value_objects.py b/alfred/domain/shared/value_objects.py index 74f8d11..30c74ee 100644 --- a/alfred/domain/shared/value_objects.py +++ b/alfred/domain/shared/value_objects.py @@ -43,29 +43,21 @@ class ImdbId: @dataclass(frozen=True) class FilePath: """ - Value object representing a file path with validation. + Value object representing a file path. - Ensures the path is valid and optionally checks existence. + Accepts either ``str`` or :class:`pathlib.Path` at construction; + the value is normalized to ``Path`` in ``__post_init__``. """ value: Path - def __init__(self, path: str | Path): - """ - Initialize FilePath. - - Args: - path: String or Path object representing the file path - """ - if isinstance(path, str): - path_obj = Path(path) - elif isinstance(path, Path): - path_obj = path - else: - raise ValidationError(f"Path must be str or Path, got {type(path)}") - - # Use object.__setattr__ because dataclass is frozen - object.__setattr__(self, "value", path_obj) + def __post_init__(self) -> None: + if isinstance(self.value, Path): + return + if isinstance(self.value, str): + object.__setattr__(self, "value", Path(self.value)) + return + raise ValidationError(f"Path must be str or Path, got {type(self.value)}") def __str__(self) -> str: return str(self.value)