[Python-checkins] bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976)

miss-islington webhook-mailer at python.org
Tue Dec 15 21:13:05 EST 2020


https://github.com/python/cpython/commit/928dbfc16c9c4715459c80fe551c74702480db8b
commit: 928dbfc16c9c4715459c80fe551c74702480db8b
branch: master
author: Jason R. Coombs <jaraco at jaraco.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-12-15T18:12:54-08:00
summary:

bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976)



Automerge-Triggered-By: GH:jaraco

files:
A Misc/NEWS.d/next/Library/2020-10-25-14-48-57.bpo-42090.Ubuc0j.rst
M Doc/library/zipfile.rst
M Lib/test/test_zipfile.py
M Lib/zipfile.py

diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst
index 7126d8bd703f6..3db55e646c47c 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 b3c24213f3474..7c09e2f51b005 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -2965,6 +2965,12 @@ def test_joinpath(self, alpharep):
         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 e1a50a3eb51d9..0eed4ce9a6344 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -2379,8 +2379,8 @@ def __str__(self):
     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 0000000000000..72f6853b50504
--- /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``.



More information about the Python-checkins mailing list