Skip to content

Commit e41031e

Browse files
committed
Create 'absolute' method and deprecate 'abspath'.
Ref #214
1 parent b991fd9 commit e41031e

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

newsfragments/214.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create 'absolute' method and deprecate 'abspath'.

path/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,18 @@ def getcwd(cls):
253253
#
254254
# --- Operations on Path strings.
255255

256-
def abspath(self):
256+
def absolute(self):
257257
""".. seealso:: :func:`os.path.abspath`"""
258258
return self._next_class(self.module.abspath(self))
259259

260+
def abspath(self):
261+
warnings.warn(
262+
".abspath is deprecated; use absolute",
263+
DeprecationWarning,
264+
stacklevel=2,
265+
)
266+
return self.absolute()
267+
260268
def normcase(self):
261269
""".. seealso:: :func:`os.path.normcase`"""
262270
return self._next_class(self.module.normcase(self))
@@ -492,10 +500,10 @@ def relpathto(self, dest):
492500
493501
If there is no relative path from `self` to `dest`, for example if
494502
they reside on different drives in Windows, then this returns
495-
``dest.abspath()``.
503+
``dest.absolute()``.
496504
"""
497-
origin = self.abspath()
498-
dest = self._next_class(dest).abspath()
505+
origin = self.absolute()
506+
dest = self._next_class(dest).absolute()
499507

500508
orig_list = origin.normcase().splitall()
501509
# Don't normcase dest! We want to preserve the case.
@@ -1502,7 +1510,7 @@ def readlinkabs(self):
15021510
.. seealso:: :meth:`readlink`, :func:`os.readlink`
15031511
"""
15041512
p = self.readlink()
1505-
return p if p.isabs() else (self.parent / p).abspath()
1513+
return p if p.isabs() else (self.parent / p).absolute()
15061514

15071515
# High-level functions from shutil
15081516
# These functions will be bound to the instance such that

test_path.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,10 @@ def test_properties(self):
134134
# .drive
135135
assert f.drive == os_choose(nt='C:', posix='')
136136

137-
def test_methods(self):
138-
# .abspath()
139-
assert Path(os.curdir).abspath() == os.getcwd()
137+
def test_absolute(self):
138+
assert Path(os.curdir).absolute() == os.getcwd()
140139

141-
# .getcwd()
140+
def test_getcwd(self):
142141
cwd = Path.getcwd()
143142
assert isinstance(cwd, Path)
144143
assert cwd == os.getcwd()
@@ -360,8 +359,8 @@ def test_symlink_none(self, tmpdir):
360359

361360
def test_readlinkabs_passthrough(self, tmpdir):
362361
link = Path(tmpdir) / 'link'
363-
Path('foo').abspath().symlink(link)
364-
assert link.readlinkabs() == Path('foo').abspath()
362+
Path('foo').absolute().symlink(link)
363+
assert link.readlinkabs() == Path('foo').absolute()
365364

366365
def test_readlinkabs_rendered(self, tmpdir):
367366
link = Path(tmpdir) / 'link'

0 commit comments

Comments
 (0)