Skip to content

Commit 465f5b0

Browse files
authored
[3.11] gh-106752: Sync with zipp 3.16.2 (GH-106757) (#106778)
* gh-106752: Sync with zipp 3.16.2 (#106757) * gh-106752: Sync with zipp 3.16.2 * Add blurb (cherry picked from commit 22980dc) * [3.11] gh-106752: Sync with zipp 3.16.2 (GH-106757) * gh-106752: Sync with zipp 3.16.2 * Add blurb. (cherry picked from commit 22980dc) Co-authored-by: Jason R. Coombs <jaraco@jaraco.com> * Remove Python 3.12 concerns from changelog.
1 parent 7dead6a commit 465f5b0

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Lib/test/test_zipfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,13 @@ def test_suffixes(self, alpharep):
34433443
e = root / '.hgrc'
34443444
assert e.suffixes == []
34453445

3446+
@pass_alpharep
3447+
def test_suffix_no_filename(self, alpharep):
3448+
alpharep.filename = None
3449+
root = zipfile.Path(alpharep)
3450+
assert root.joinpath('example').suffix == ""
3451+
assert root.joinpath('example').suffixes == []
3452+
34463453
@pass_alpharep
34473454
def test_stem(self, alpharep):
34483455
"""
@@ -3460,6 +3467,8 @@ def test_stem(self, alpharep):
34603467
d = root / "d"
34613468
assert d.stem == "d"
34623469

3470+
assert (root / ".gitignore").stem == ".gitignore"
3471+
34633472
@pass_alpharep
34643473
def test_root_parent(self, alpharep):
34653474
root = zipfile.Path(alpharep)

Lib/zipfile.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,21 +2420,24 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
24202420
encoding, args, kwargs = _extract_text_encoding(*args, **kwargs)
24212421
return io.TextIOWrapper(stream, encoding, *args, **kwargs)
24222422

2423+
def _base(self):
2424+
return pathlib.PurePosixPath(self.at or self.root.filename)
2425+
24232426
@property
24242427
def name(self):
2425-
return pathlib.Path(self.at).name or self.filename.name
2428+
return self._base().name
24262429

24272430
@property
24282431
def suffix(self):
2429-
return pathlib.Path(self.at).suffix or self.filename.suffix
2432+
return self._base().suffix
24302433

24312434
@property
24322435
def suffixes(self):
2433-
return pathlib.Path(self.at).suffixes or self.filename.suffixes
2436+
return self._base().suffixes
24342437

24352438
@property
24362439
def stem(self):
2437-
return pathlib.Path(self.at).stem or self.filename.stem
2440+
return self._base().stem
24382441

24392442
@property
24402443
def filename(self):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed several bug in zipfile.Path in
2+
``name``/``suffix``/``suffixes``/``stem`` operations when no filename is
3+
present and the Path is not at the root of the zipfile.

0 commit comments

Comments
 (0)