mirror of
https://github.com/python/cpython.git
synced 2025-07-22 02:35:22 +00:00
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.
This commit is contained in:
parent
beb80d11ec
commit
5d8a3e74b5
2 changed files with 26 additions and 32 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue