Skip to content

[3.11] gh-106752: Sync with zipp 3.16.2 (GH-106757) #106778

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
Jul 15, 2023
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
9 changes: 9 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,13 @@ def test_suffixes(self, alpharep):
e = root / '.hgrc'
assert e.suffixes == []

@pass_alpharep
def test_suffix_no_filename(self, alpharep):
alpharep.filename = None
root = zipfile.Path(alpharep)
assert root.joinpath('example').suffix == ""
assert root.joinpath('example').suffixes == []

@pass_alpharep
def test_stem(self, alpharep):
"""
Expand All @@ -3460,6 +3467,8 @@ def test_stem(self, alpharep):
d = root / "d"
assert d.stem == "d"

assert (root / ".gitignore").stem == ".gitignore"

@pass_alpharep
def test_root_parent(self, alpharep):
root = zipfile.Path(alpharep)
Expand Down
11 changes: 7 additions & 4 deletions Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2420,21 +2420,24 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
encoding, args, kwargs = _extract_text_encoding(*args, **kwargs)
return io.TextIOWrapper(stream, encoding, *args, **kwargs)

def _base(self):
return pathlib.PurePosixPath(self.at or self.root.filename)

@property
def name(self):
return pathlib.Path(self.at).name or self.filename.name
return self._base().name

@property
def suffix(self):
return pathlib.Path(self.at).suffix or self.filename.suffix
return self._base().suffix

@property
def suffixes(self):
return pathlib.Path(self.at).suffixes or self.filename.suffixes
return self._base().suffixes

@property
def stem(self):
return pathlib.Path(self.at).stem or self.filename.stem
return self._base().stem

@property
def filename(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed several bug in zipfile.Path in
``name``/``suffix``/``suffixes``/``stem`` operations when no filename is
present and the Path is not at the root of the zipfile.