Skip to content

Commit

Permalink
Update normalizers.py
Browse files Browse the repository at this point in the history
- broadened scope of `Path.resolve` for improved robustness 
- document implicit exception.
- improved error message.
- corrected typo in docstring.
  • Loading branch information
knutnergaard authored Nov 21, 2024
1 parent 9f6827d commit 3e09e07
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Lib/fontParts/base/normalizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,17 +1145,16 @@ def normalizeFilePath(value: Union[str, Path]) -> str:
Relative paths are resolved automatically.

:param value: The file path to normalize as a :class:`str` or :class:`pathlib.Path`.
:return: A :class:`str` representing the noramlized file path.
:return: A :class:`str` representing the normalized file path.
:raises TypeError if `value` is not a :class:`str` or :class:`pathlib.Path`.
:raises FileNotFoundError: If the file path cannot be resolved because it does not exist.

"""
if not isinstance(value, (str, Path)):
raise TypeError(
f"File paths must be strings or Path, not {type(value).__name__}."
f"File paths must be strings or Path objects, not {type(value).__name__}."
)
if isinstance(value, Path) or value.startswith("."):
return str(Path(value).resolve())
return str(value)
return str(Path(value).resolve())


# Interpolation
Expand Down

0 comments on commit 3e09e07

Please sign in to comment.