Skip to content

Commit

Permalink
In readlink, prefer the display path to the substitute path.
Browse files Browse the repository at this point in the history
Closes #222
  • Loading branch information
jaraco committed Apr 8, 2024
1 parent 26a9bb4 commit b991fd9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/222.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In readlink, prefer the display path to the substitute path.
4 changes: 2 additions & 2 deletions path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
from typing_extensions import Literal

from . import classes, masks, matchers
from .compat.py38 import removesuffix
from .compat.py38 import removeprefix, removesuffix

__all__ = ['Path', 'TempDir']

Expand Down Expand Up @@ -1492,7 +1492,7 @@ def readlink(self):
.. seealso:: :meth:`readlinkabs`, :func:`os.readlink`
"""
return self._next_class(os.readlink(self))
return self._next_class(removeprefix(os.readlink(self), '\\\\?\\'))

def readlinkabs(self):
"""Return the path to which this symbolic link points.
Expand Down
9 changes: 9 additions & 0 deletions path/compat/py38.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ def removesuffix(self, suffix):
return self[: -len(suffix)]
else:
return self[:]

def removeprefix(self, prefix):
if self.startswith(prefix):
return self[len(prefix) :]
else:
return self[:]
else:

def removesuffix(self, suffix):
return self.removesuffix(suffix)

def removeprefix(self, prefix):
return self.removeprefix(prefix)

0 comments on commit b991fd9

Please sign in to comment.