]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976)
authorJason R. Coombs <jaraco@jaraco.com>
Wed, 16 Dec 2020 02:12:54 +0000 (21:12 -0500)
committerGitHub <noreply@github.com>
Wed, 16 Dec 2020 02:12:54 +0000 (18:12 -0800)
Automerge-Triggered-By: GH:jaraco
Doc/library/zipfile.rst
Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/NEWS.d/next/Library/2020-10-25-14-48-57.bpo-42090.Ubuc0j.rst [new file with mode: 0644]

index 7126d8bd703f62902eb400059132529bd393b8bc..3db55e646c47cc5a73f3ba7052a0b4f7885c5872 100644 (file)
@@ -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:
 
index b3c24213f3474d01362b41eb661d7e4ea211c968..7c09e2f51b005a1a68f388c91714b950a33eefba 100644 (file)
@@ -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)
index e1a50a3eb51d95a0f1e18afb29e72b5d4a2b334c..0eed4ce9a63441e43bd36e8a05990eeb4bf9f980 100644 (file)
@@ -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 (file)
index 0000000..72f6853
--- /dev/null
@@ -0,0 +1,2 @@
+``zipfile.Path.joinpath`` now accepts arbitrary arguments, same as
+``pathlib.Path.joinpath``.