summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/zipfile.rst15
-rw-r--r--Lib/test/test_zipfile.py6
-rw-r--r--Lib/zipfile.py4
-rw-r--r--Misc/NEWS.d/next/Library/2020-10-25-14-48-57.bpo-42090.Ubuc0j.rst2
4 files changed, 24 insertions, 3 deletions
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst
index 7126d8b..3db55e6 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 b3c2421..7c09e2f 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -2966,6 +2966,12 @@ class TestPath(unittest.TestCase):
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)
a = root / "a.txt"
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index e1a50a3..0eed4ce 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 0000000..72f6853
--- /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``.