pathlib: add absolutepath() as alternative to Path.resolve()

Didn't call it absolute or absolute_path to avoid conflicts with
possible variable names.

Didn't call it abspath to avoid confusion with os.path.abspath.
This commit is contained in:
Ran Benita 2020-08-05 18:36:41 +03:00
parent e0d0951945
commit 9e55288ba4
1 changed files with 9 additions and 0 deletions

View File

@ -571,6 +571,15 @@ def visit(
yield from visit(entry.path, recurse) yield from visit(entry.path, recurse)
def absolutepath(path: Union[Path, str]) -> Path:
"""Convert a path to an absolute path using os.path.abspath.
Prefer this over Path.resolve() (see #6523).
Prefer this over Path.absolute() (not public, doesn't normalize).
"""
return Path(os.path.abspath(str(path)))
def commonpath(path1: Path, path2: Path) -> Optional[Path]: def commonpath(path1: Path, path2: Path) -> Optional[Path]:
"""Return the common part shared with the other path, or None if there is """Return the common part shared with the other path, or None if there is
no common part.""" no common part."""