From: Jason R. Coombs Date: Wed, 16 Dec 2020 02:12:54 +0000 (-0500) Subject: bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976) X-Git-Tag: v3.10.0a4~165 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=928dbfc16c9c4715459c80fe551c74702480db8b;p=thirdparty%2FPython%2Fcpython.git bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976) Automerge-Triggered-By: GH:jaraco --- diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst index 7126d8bd703f..3db55e646c47 100644 --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -483,7 +483,7 @@ Path Objects Path objects expose the following features of :mod:`pathlib.Path` objects: -Path objects are traversable using the ``/`` operator. +Path objects are traversable using the ``/`` operator or ``joinpath``. .. attribute:: Path.name @@ -532,6 +532,19 @@ Path objects are traversable using the ``/`` operator. Read the current file as bytes. +.. method:: Path.joinpath(*other) + + Return a new Path object with each of the *other* arguments + joined. The following are equivalent:: + + >>> Path(...).joinpath('child').joinpath('grandchild') + >>> Path(...).joinpath('child', 'grandchild') + >>> Path(...) / 'child' / 'grandchild' + + .. versionchanged:: 3.10 + Prior to 3.10, ``joinpath`` was undocumented and accepted + exactly one parameter. + .. _pyzipfile-objects: diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index b3c24213f347..7c09e2f51b00 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -2965,6 +2965,12 @@ class TestPath(unittest.TestCase): e = root.joinpath("b").joinpath("d").joinpath("e.txt") assert e.read_text() == "content of e" + @pass_alpharep + def test_joinpath_multiple(self, alpharep): + root = zipfile.Path(alpharep) + e = root.joinpath("b", "d", "e.txt") + assert e.read_text() == "content of e" + @pass_alpharep def test_traverse_truediv(self, alpharep): root = zipfile.Path(alpharep) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index e1a50a3eb51d..0eed4ce9a634 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -2379,8 +2379,8 @@ class Path: def __repr__(self): return self.__repr.format(self=self) - def joinpath(self, add): - next = posixpath.join(self.at, add) + def joinpath(self, *other): + next = posixpath.join(self.at, *other) return self._next(self.root.resolve_dir(next)) __truediv__ = joinpath diff --git a/Misc/NEWS.d/next/Library/2020-10-25-14-48-57.bpo-42090.Ubuc0j.rst b/Misc/NEWS.d/next/Library/2020-10-25-14-48-57.bpo-42090.Ubuc0j.rst new file mode 100644 index 000000000000..72f6853b5050 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-10-25-14-48-57.bpo-42090.Ubuc0j.rst @@ -0,0 +1,2 @@ +``zipfile.Path.joinpath`` now accepts arbitrary arguments, same as +``pathlib.Path.joinpath``.