summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib/_local.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-11-30 18:39:39 (GMT)
committerGitHub <noreply@github.com>2024-11-30 18:39:39 (GMT)
commit328187cc4fcdd578db42cf6a16c197c3382157a7 (patch)
tree0e3801a45867fa87d4a7cfb5b7dcfda06d702a97 /Lib/pathlib/_local.py
parent4e0a4cafe8d8ecb43db62aed1d5671af583104e7 (diff)
downloadcpython-328187cc4fcdd578db42cf6a16c197c3382157a7.zip
cpython-328187cc4fcdd578db42cf6a16c197c3382157a7.tar.gz
cpython-328187cc4fcdd578db42cf6a16c197c3382157a7.tar.bz2
GH-127381: pathlib ABCs: remove `PathBase.cwd()` and `home()` (#127427)
These classmethods presume that the user has retained the original `__init__()` signature, which may not be the case. Also, many virtual filesystems don't provide current or home directories.
Diffstat (limited to 'Lib/pathlib/_local.py')
-rw-r--r--Lib/pathlib/_local.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py
index 25c1e3f..b5d9dc4 100644
--- a/Lib/pathlib/_local.py
+++ b/Lib/pathlib/_local.py
@@ -726,6 +726,14 @@ class Path(PathBase, PurePath):
tail.extend(self._tail)
return self._from_parsed_parts(drive, root, tail)
+ @classmethod
+ def cwd(cls):
+ """Return a new path pointing to the current working directory."""
+ cwd = os.getcwd()
+ path = cls(cwd)
+ path._str = cwd # getcwd() returns a normalized path
+ return path
+
def resolve(self, strict=False):
"""
Make the path absolute, resolving all symlinks on the way and also
@@ -908,6 +916,15 @@ class Path(PathBase, PurePath):
return self
@classmethod
+ def home(cls):
+ """Return a new path pointing to expanduser('~').
+ """
+ homedir = os.path.expanduser("~")
+ if homedir == "~":
+ raise RuntimeError("Could not determine home directory.")
+ return cls(homedir)
+
+ @classmethod
def from_uri(cls, uri):
"""Return a new path from the given 'file' URI."""
if not uri.startswith('file:'):