Skip to content

Commit 7a3cffa

Browse files
jaracolisroach
authored andcommitted
bpo-37520: Correct behavior for zipfile.Path.parent (pythonGH-14638)
* bpo-37520: Correct behavior for zipfile.Path.parent * πŸ“œπŸ€– Added by blurb_it.
1 parent ee238c8 commit 7a3cffa

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

β€ŽLib/test/test_zipfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,5 +2514,16 @@ def test_parent(self):
25142514
assert (root / 'a').parent.at == ''
25152515
assert (root / 'a' / 'b').parent.at == 'a/'
25162516

2517+
def test_dir_parent(self):
2518+
for zipfile_abcde in self.zipfile_abcde():
2519+
root = zipfile.Path(zipfile_abcde)
2520+
assert (root / 'b').parent.at == ''
2521+
assert (root / 'b/').parent.at == ''
2522+
2523+
def test_missing_dir_parent(self):
2524+
for zipfile_abcde in self.zipfile_abcde():
2525+
root = zipfile.Path(zipfile_abcde)
2526+
assert (root / 'missing dir/').parent.at == ''
2527+
25172528
if __name__ == "__main__":
25182529
unittest.main()

β€ŽLib/zipfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ def _add_implied_dirs(names):
22362236

22372237
@property
22382238
def parent(self):
2239-
parent_at = posixpath.dirname(self.at)
2239+
parent_at = posixpath.dirname(self.at.rstrip('/'))
22402240
if parent_at:
22412241
parent_at += '/'
22422242
return self._next(parent_at)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Correct behavior for zipfile.Path.parent when the path object identifies a subdirectory.

0 commit comments

Comments
Β (0)