summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-01-10 01:12:58 (GMT)
committerGitHub <noreply@github.com>2024-01-10 01:12:58 (GMT)
commit5d8a3e74b51a59752f24cb869e7daa065b673f83 (patch)
tree8504e1f5ee9e1f5b5a1efd7e602f7b08365c4bb2 /Lib/pathlib
parentbeb80d11ec0ddaf00a97f8a38ec9eae68e07c28e (diff)
downloadcpython-5d8a3e74b51a59752f24cb869e7daa065b673f83.zip
cpython-5d8a3e74b51a59752f24cb869e7daa065b673f83.tar.gz
cpython-5d8a3e74b51a59752f24cb869e7daa065b673f83.tar.bz2
pathlib ABCs: Require one or more initialiser arguments (#113885)
Refuse to guess what a user means when they initialise a pathlib ABC without any positional arguments. In mainline pathlib it's normalised to `.`, but in the ABCs this guess isn't appropriate; for example, the path type may not represent the current directory as `.`, or may have no concept of a "current directory" at all.
Diffstat (limited to 'Lib/pathlib')
-rw-r--r--Lib/pathlib/_abc.py10
1 files changed, 2 insertions, 8 deletions
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
index 6a19284..2fc087d 100644
--- a/Lib/pathlib/_abc.py
+++ b/Lib/pathlib/_abc.py
@@ -167,13 +167,7 @@ class PurePathBase:
def __str__(self):
"""Return the string representation of the path, suitable for
passing to system calls."""
- paths = self._raw_paths
- if len(paths) == 1:
- return paths[0]
- elif paths:
- return self.pathmod.join(*paths)
- else:
- return ''
+ return self.pathmod.join(*self._raw_paths)
def as_posix(self):
"""Return the string representation of the path with forward (/)
@@ -838,7 +832,7 @@ class PathBase(PurePathBase):
# enable users to replace the implementation of 'absolute()' in a
# subclass and benefit from the new behaviour here. This works because
# os.path.abspath('.') == os.getcwd().
- return cls().absolute()
+ return cls('').absolute()
def expanduser(self):
""" Return a new path with expanded ~ and ~user constructs