Skip to content

Commit b991fd9

Browse files
committed
In readlink, prefer the display path to the substitute path.
Closes #222
1 parent 26a9bb4 commit b991fd9

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

newsfragments/222.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In readlink, prefer the display path to the substitute path.

path/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
from typing_extensions import Literal
8080

8181
from . import classes, masks, matchers
82-
from .compat.py38 import removesuffix
82+
from .compat.py38 import removeprefix, removesuffix
8383

8484
__all__ = ['Path', 'TempDir']
8585

@@ -1492,7 +1492,7 @@ def readlink(self):
14921492
14931493
.. seealso:: :meth:`readlinkabs`, :func:`os.readlink`
14941494
"""
1495-
return self._next_class(os.readlink(self))
1495+
return self._next_class(removeprefix(os.readlink(self), '\\\\?\\'))
14961496

14971497
def readlinkabs(self):
14981498
"""Return the path to which this symbolic link points.

path/compat/py38.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ def removesuffix(self, suffix):
88
return self[: -len(suffix)]
99
else:
1010
return self[:]
11+
12+
def removeprefix(self, prefix):
13+
if self.startswith(prefix):
14+
return self[len(prefix) :]
15+
else:
16+
return self[:]
1117
else:
1218

1319
def removesuffix(self, suffix):
1420
return self.removesuffix(suffix)
21+
22+
def removeprefix(self, prefix):
23+
return self.removeprefix(prefix)

0 commit comments

Comments
 (0)