pathlib: make `absolutepath` support `os.PathLike[str]`

This slightly simplifies a bit of path.
This commit is contained in:
Ran Benita 2024-04-27 11:03:52 +03:00
parent 1a332802ff
commit 80ca255d42
2 changed files with 3 additions and 3 deletions

View File

@ -765,7 +765,7 @@ class Item(Node, abc.ABC):
and lineno is a 0-based line number. and lineno is a 0-based line number.
""" """
location = self.reportinfo() location = self.reportinfo()
path = absolutepath(os.fspath(location[0])) path = absolutepath(location[0])
relfspath = self.session._node_location_to_relpath(path) relfspath = self.session._node_location_to_relpath(path)
assert type(location[2]) is str assert type(location[2]) is str
return (relfspath, location[1], location[2]) return (relfspath, location[1], location[2])

View File

@ -924,13 +924,13 @@ def visit(
yield from visit(entry.path, recurse) yield from visit(entry.path, recurse)
def absolutepath(path: Union[Path, str]) -> Path: def absolutepath(path: "Union[str, os.PathLike[str]]") -> Path:
"""Convert a path to an absolute path using os.path.abspath. """Convert a path to an absolute path using os.path.abspath.
Prefer this over Path.resolve() (see #6523). Prefer this over Path.resolve() (see #6523).
Prefer this over Path.absolute() (not public, doesn't normalize). Prefer this over Path.absolute() (not public, doesn't normalize).
""" """
return Path(os.path.abspath(str(path))) return Path(os.path.abspath(path))
def commonpath(path1: Path, path2: Path) -> Optional[Path]: def commonpath(path1: Path, path2: Path) -> Optional[Path]: