Skip to content

Commit

Permalink
bpo-37520: Correct behavior for zipfile.Path.parent (pythonGH-14638)
Browse files Browse the repository at this point in the history
* bpo-37520: Correct behavior for zipfile.Path.parent

* πŸ“œπŸ€– Added by blurb_it.
  • Loading branch information
jaraco authored Jul 7, 2019
1 parent f6cdd3f commit 38f44b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2514,5 +2514,16 @@ def test_parent(self):
assert (root / 'a').parent.at == ''
assert (root / 'a' / 'b').parent.at == 'a/'

def test_dir_parent(self):
for zipfile_abcde in self.zipfile_abcde():
root = zipfile.Path(zipfile_abcde)
assert (root / 'b').parent.at == ''
assert (root / 'b/').parent.at == ''

def test_missing_dir_parent(self):
for zipfile_abcde in self.zipfile_abcde():
root = zipfile.Path(zipfile_abcde)
assert (root / 'missing dir/').parent.at == ''

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ def _add_implied_dirs(names):

@property
def parent(self):
parent_at = posixpath.dirname(self.at)
parent_at = posixpath.dirname(self.at.rstrip('/'))
if parent_at:
parent_at += '/'
return self._next(parent_at)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correct behavior for zipfile.Path.parent when the path object identifies a subdirectory.

0 comments on commit 38f44b4

Please sign in to comment.