Skip to content
Closed
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
8 changes: 7 additions & 1 deletion Lib/test/test_zipfile/_path/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,15 @@ def test_root_unnamed(self, alpharep):

# .name and .parent should still work on subs
sub = root / "b"
assert sub.name == "b"
self.assertEqual(sub.name, "b")
assert sub.parent

# It should be possible to get the repr and str
self.assertEqual(str(root), ":memory:/")
self.assertEqual(repr(root), "Path(None, '')")
self.assertEqual(str(sub), ":memory:/b/")
self.assertEqual(repr(sub), "Path(None, 'b/')")

@pass_alpharep
def test_match_and_glob(self, alpharep):
root = zipfile.Path(alpharep)
Expand Down
4 changes: 3 additions & 1 deletion Lib/zipfile/_path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ def relative_to(self, other, *extra):
return posixpath.relpath(str(self), str(other.joinpath(*extra)))

def __str__(self):
return posixpath.join(self.root.filename, self.at)
if (filename := self.root.filename) is None:
filename = ":memory:"
return posixpath.join(filename, self.at)

def __repr__(self):
return self.__repr.format(self=self)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where ``str(zipfile.Path(zipfile.ZipFile(io.BytesIO(data))))`` would raise a ``TypeError``
Loading