Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stop returning unnormalised path from __fspath__()
  • Loading branch information
barneygale committed Mar 17, 2023
commit 9650dca6ee972f8bb53198bfc7860a1e6dc510b0
5 changes: 1 addition & 4 deletions Lib/importlib/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,7 @@ def read_text(self, filename):
NotADirectoryError,
PermissionError,
):
path = self._path
if filename:
path /= filename
return path.read_text(encoding='utf-8')
return self._path.joinpath(filename).read_text(encoding='utf-8')

read_text.__doc__ = Distribution.read_text.__doc__

Expand Down
9 changes: 2 additions & 7 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,7 @@ def __str__(self):
return self._str

def __fspath__(self):
try:
return self._fspath or '.'
except AttributeError:
# The _from_parsed_parts() constructor does not set _fspath.
self._fspath = str(self)
return self._fspath
return str(self)

def as_posix(self):
"""Return the string representation of the path with forward (/)
Expand All @@ -355,7 +350,7 @@ def as_posix(self):
def __bytes__(self):
"""Return the bytes representation of the path. This is only
recommended to use under Unix."""
return os.fsencode(str(self))
return os.fsencode(self)

def __repr__(self):
return "{}({!r})".format(self.__class__.__name__, self.as_posix())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Speed up construction and joining of :class:`pathlib.PurePath` objects by
deferring path parsing and normalization until needed. Some path object
operations are 2-4x faster as a result of this change. An unnormalized path
is now returned by :func:`os.fspath` when a pathlib path object is given.
operations are 2-4x faster as a result of this change.