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

Automerge-Triggered-By: GH:jaraco
This commit is contained in:
Jason R. Coombs 2020-12-15 21:12:54 -05:00 committed by GitHub
parent b230409f21
commit 928dbfc16c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View File

@ -483,7 +483,7 @@ Path Objects
Path objects expose the following features of :mod:`pathlib.Path` Path objects expose the following features of :mod:`pathlib.Path`
objects: objects:
Path objects are traversable using the ``/`` operator. Path objects are traversable using the ``/`` operator or ``joinpath``.
.. attribute:: Path.name .. attribute:: Path.name
@ -532,6 +532,19 @@ Path objects are traversable using the ``/`` operator.
Read the current file as bytes. 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: .. _pyzipfile-objects:

View File

@ -2965,6 +2965,12 @@ class TestPath(unittest.TestCase):
e = root.joinpath("b").joinpath("d").joinpath("e.txt") e = root.joinpath("b").joinpath("d").joinpath("e.txt")
assert e.read_text() == "content of e" 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 @pass_alpharep
def test_traverse_truediv(self, alpharep): def test_traverse_truediv(self, alpharep):
root = zipfile.Path(alpharep) root = zipfile.Path(alpharep)

View File

@ -2379,8 +2379,8 @@ class Path:
def __repr__(self): def __repr__(self):
return self.__repr.format(self=self) return self.__repr.format(self=self)
def joinpath(self, add): def joinpath(self, *other):
next = posixpath.join(self.at, add) next = posixpath.join(self.at, *other)
return self._next(self.root.resolve_dir(next)) return self._next(self.root.resolve_dir(next))
__truediv__ = joinpath __truediv__ = joinpath

View File

@ -0,0 +1,2 @@
``zipfile.Path.joinpath`` now accepts arbitrary arguments, same as
``pathlib.Path.joinpath``.