bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976)
Automerge-Triggered-By: GH:jaraco
This commit is contained in:
parent
b230409f21
commit
928dbfc16c
|
@ -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:
|
||||
|
||||
|
|
|
@ -2965,6 +2965,12 @@ class TestPath(unittest.TestCase):
|
|||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
``zipfile.Path.joinpath`` now accepts arbitrary arguments, same as
|
||||
``pathlib.Path.joinpath``.
|
Loading…
Reference in New Issue