[Python-checkins] bpo-37520: Correct behavior for zipfile.Path.parent (GH-14638) (GH-14641)
Jason R. Coombs
webhook-mailer at python.org
Sun Jul 7 18:05:57 EDT 2019
https://github.com/python/cpython/commit/66905d14672517d50dc8ba516b9839f9ddbcc131
commit: 66905d14672517d50dc8ba516b9839f9ddbcc131
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Jason R. Coombs <jaraco at jaraco.com>
date: 2019-07-07T18:05:53-04:00
summary:
bpo-37520: Correct behavior for zipfile.Path.parent (GH-14638) (GH-14641)
* bpo-37520: Correct behavior for zipfile.Path.parent
* 📜🤖 Added by blurb_it.
(cherry picked from commit 38f44b4a4adc37e8f5f8971917d8b3145f351a56)
Co-authored-by: Jason R. Coombs <jaraco at jaraco.com>
files:
A Misc/NEWS.d/next/Library/2019-07-07-21-09-08.bpo-37520.Gg0KD6.rst
M Lib/test/test_zipfile.py
M Lib/zipfile.py
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 19b550f80187..0c8ffcdbf14a 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -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()
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 62f2fd27d3ce..3c1f1235034a 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -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)
diff --git a/Misc/NEWS.d/next/Library/2019-07-07-21-09-08.bpo-37520.Gg0KD6.rst b/Misc/NEWS.d/next/Library/2019-07-07-21-09-08.bpo-37520.Gg0KD6.rst
new file mode 100644
index 000000000000..6584d3ebe1ed
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-07-07-21-09-08.bpo-37520.Gg0KD6.rst
@@ -0,0 +1 @@
+Correct behavior for zipfile.Path.parent when the path object identifies a subdirectory.
\ No newline at end of file
More information about the Python-checkins
mailing list