Skip to content

Commit

Permalink
Create 'absolute' method and deprecate 'abspath'.
Browse files Browse the repository at this point in the history
Ref #214
  • Loading branch information
jaraco committed Apr 8, 2024
1 parent b991fd9 commit e41031e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions newsfragments/214.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create 'absolute' method and deprecate 'abspath'.
18 changes: 13 additions & 5 deletions path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,18 @@ def getcwd(cls):
#
# --- Operations on Path strings.

def abspath(self):
def absolute(self):
""".. seealso:: :func:`os.path.abspath`"""
return self._next_class(self.module.abspath(self))

def abspath(self):
warnings.warn(
".abspath is deprecated; use absolute",
DeprecationWarning,
stacklevel=2,
)
return self.absolute()

def normcase(self):
""".. seealso:: :func:`os.path.normcase`"""
return self._next_class(self.module.normcase(self))
Expand Down Expand Up @@ -492,10 +500,10 @@ def relpathto(self, dest):
If there is no relative path from `self` to `dest`, for example if
they reside on different drives in Windows, then this returns
``dest.abspath()``.
``dest.absolute()``.
"""
origin = self.abspath()
dest = self._next_class(dest).abspath()
origin = self.absolute()
dest = self._next_class(dest).absolute()

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

# High-level functions from shutil
# These functions will be bound to the instance such that
Expand Down
11 changes: 5 additions & 6 deletions test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ def test_properties(self):
# .drive
assert f.drive == os_choose(nt='C:', posix='')

def test_methods(self):
# .abspath()
assert Path(os.curdir).abspath() == os.getcwd()
def test_absolute(self):
assert Path(os.curdir).absolute() == os.getcwd()

# .getcwd()
def test_getcwd(self):
cwd = Path.getcwd()
assert isinstance(cwd, Path)
assert cwd == os.getcwd()
Expand Down Expand Up @@ -360,8 +359,8 @@ def test_symlink_none(self, tmpdir):

def test_readlinkabs_passthrough(self, tmpdir):
link = Path(tmpdir) / 'link'
Path('foo').abspath().symlink(link)
assert link.readlinkabs() == Path('foo').abspath()
Path('foo').absolute().symlink(link)
assert link.readlinkabs() == Path('foo').absolute()

def test_readlinkabs_rendered(self, tmpdir):
link = Path(tmpdir) / 'link'
Expand Down

0 comments on commit e41031e

Please sign in to comment.