Skip to content

bpo-42090: zipfile.Path.joinpath now accepts multiple arguments #22976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Doc/library/zipfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:

Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``zipfile.Path.joinpath`` now accepts arbitrary arguments, same as
``pathlib.Path.joinpath``.