Skip to content

Commit 928dbfc

Browse files
authored
bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976)
Automerge-Triggered-By: GH:jaraco
1 parent b230409 commit 928dbfc

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

Doc/library/zipfile.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ Path Objects
483483
Path objects expose the following features of :mod:`pathlib.Path`
484484
objects:
485485

486-
Path objects are traversable using the ``/`` operator.
486+
Path objects are traversable using the ``/`` operator or ``joinpath``.
487487

488488
.. attribute:: Path.name
489489

@@ -532,6 +532,19 @@ Path objects are traversable using the ``/`` operator.
532532

533533
Read the current file as bytes.
534534

535+
.. method:: Path.joinpath(*other)
536+
537+
Return a new Path object with each of the *other* arguments
538+
joined. The following are equivalent::
539+
540+
>>> Path(...).joinpath('child').joinpath('grandchild')
541+
>>> Path(...).joinpath('child', 'grandchild')
542+
>>> Path(...) / 'child' / 'grandchild'
543+
544+
.. versionchanged:: 3.10
545+
Prior to 3.10, ``joinpath`` was undocumented and accepted
546+
exactly one parameter.
547+
535548

536549
.. _pyzipfile-objects:
537550

Lib/test/test_zipfile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,12 @@ def test_joinpath(self, alpharep):
29652965
e = root.joinpath("b").joinpath("d").joinpath("e.txt")
29662966
assert e.read_text() == "content of e"
29672967

2968+
@pass_alpharep
2969+
def test_joinpath_multiple(self, alpharep):
2970+
root = zipfile.Path(alpharep)
2971+
e = root.joinpath("b", "d", "e.txt")
2972+
assert e.read_text() == "content of e"
2973+
29682974
@pass_alpharep
29692975
def test_traverse_truediv(self, alpharep):
29702976
root = zipfile.Path(alpharep)

Lib/zipfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,8 +2379,8 @@ def __str__(self):
23792379
def __repr__(self):
23802380
return self.__repr.format(self=self)
23812381

2382-
def joinpath(self, add):
2383-
next = posixpath.join(self.at, add)
2382+
def joinpath(self, *other):
2383+
next = posixpath.join(self.at, *other)
23842384
return self._next(self.root.resolve_dir(next))
23852385

23862386
__truediv__ = joinpath
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``zipfile.Path.joinpath`` now accepts arbitrary arguments, same as
2+
``pathlib.Path.joinpath``.

0 commit comments

Comments
 (0)