]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-135276: Refresh `zipfile.Path` from zipp 3.23 (GH-135277) (#135279)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 8 Jun 2025 21:56:35 +0000 (23:56 +0200)
committerGitHub <noreply@github.com>
Sun, 8 Jun 2025 21:56:35 +0000 (17:56 -0400)
* gh-135276: Refresh `zipfile.Path` from zipp 3.23 (GH-135277)

Apply changes from zipp 3.23
(cherry picked from commit 8d6eb0c26276c4013346622580072908d46d2341)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
* Removed features slated for Python 3.15 only.

---------

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Lib/test/test_zipfile/_path/_test_params.py
Lib/test/test_zipfile/_path/test_complexity.py
Lib/test/test_zipfile/_path/test_path.py
Lib/test/test_zipfile/_path/write-alpharep.py
Lib/zipfile/_path/__init__.py
Lib/zipfile/_path/glob.py
Misc/NEWS.d/next/Library/2025-06-08-14-50-34.gh-issue-135276.ZLUhV1.rst [new file with mode: 0644]

index bc95b4ebf4a168c1798af262cf8e750c56ed4144..00a9eaf2f99c1aef7e008477582761d5d5dcf277 100644 (file)
@@ -1,5 +1,5 @@
-import types
 import functools
+import types
 
 from ._itertools import always_iterable
 
index b505dd7c3764623ee566ed5a4ce9910647d960ee..7c108fc6ab8191db8e48f8d1587d5a6aa5dfcd4f 100644 (file)
@@ -8,10 +8,8 @@ import zipfile
 
 from ._functools import compose
 from ._itertools import consume
-
 from ._support import import_or_skip
 
-
 big_o = import_or_skip('big_o')
 pytest = import_or_skip('pytest')
 
index aba515536f0c1a57c29b1531b5bbd2d71db7ee21..f46b676e1ef2d88df8b17ce6b11863bde4902d14 100644 (file)
@@ -1,6 +1,6 @@
+import contextlib
 import io
 import itertools
-import contextlib
 import pathlib
 import pickle
 import stat
@@ -10,12 +10,11 @@ import unittest
 import zipfile
 import zipfile._path
 
-from test.support.os_helper import temp_dir, FakePath
+from test.support.os_helper import FakePath, temp_dir
 
 from ._functools import compose
 from ._itertools import Counter
-
-from ._test_params import parameterize, Invoked
+from ._test_params import Invoked, parameterize
 
 
 class jaraco:
@@ -194,10 +193,10 @@ class TestPath(unittest.TestCase):
         """EncodingWarning must blame the read_text and open calls."""
         assert sys.flags.warn_default_encoding
         root = zipfile.Path(alpharep)
-        with self.assertWarns(EncodingWarning) as wc:
+        with self.assertWarns(EncodingWarning) as wc:  # noqa: F821 (astral-sh/ruff#13296)
             root.joinpath("a.txt").read_text()
         assert __file__ == wc.filename
-        with self.assertWarns(EncodingWarning) as wc:
+        with self.assertWarns(EncodingWarning) as wc:  # noqa: F821 (astral-sh/ruff#13296)
             root.joinpath("a.txt").open("r").close()
         assert __file__ == wc.filename
 
@@ -365,6 +364,17 @@ class TestPath(unittest.TestCase):
         root = zipfile.Path(alpharep)
         assert root.name == 'alpharep.zip' == root.filename.name
 
+    @pass_alpharep
+    def test_root_on_disk(self, alpharep):
+        """
+        The name/stem of the root should match the zipfile on disk.
+
+        This condition must hold across platforms.
+        """
+        root = zipfile.Path(self.zipfile_ondisk(alpharep))
+        assert root.name == 'alpharep.zip' == root.filename.name
+        assert root.stem == 'alpharep' == root.filename.stem
+
     @pass_alpharep
     def test_suffix(self, alpharep):
         """
index 48c09b537179fd2489fc236239c81d43b11135e7..7418391abadde5e7a9af8d0de59de0a70bd56249 100644 (file)
@@ -1,4 +1,3 @@
 from . import test_path
 
-
 __name__ == '__main__' and test_path.build_alpharep_fixture().extractall('alpharep')
index b7d4f8906e8bed046c2015fda042dc7f481a5f2d..02f81171b4f11b7dbcf5bd775b244d3fdf8e4118 100644 (file)
@@ -7,19 +7,18 @@ https://github.com/python/importlib_metadata/wiki/Development-Methodology
 for more detail.
 """
 
+import contextlib
 import io
-import posixpath
-import zipfile
 import itertools
-import contextlib
 import pathlib
+import posixpath
 import re
 import stat
 import sys
+import zipfile
 
 from .glob import Translator
 
-
 __all__ = ['Path']
 
 
@@ -192,11 +191,13 @@ class FastLookup(CompleteDirs):
         self.__lookup = super()._name_set()
         return self.__lookup
 
-
 def _extract_text_encoding(encoding=None, *args, **kwargs):
     # compute stack level so that the caller of the caller sees any warning.
     is_pypy = sys.implementation.name == 'pypy'
-    stack_level = 3 + is_pypy
+    # PyPy no longer special cased after 7.3.19 (or maybe 7.3.18)
+    # See jaraco/zipp#143
+    is_old_pypi = is_pypy and sys.pypy_version_info < (7, 3, 19)
+    stack_level = 3 + is_old_pypi
     return io.text_encoding(encoding, stack_level), args, kwargs
 
 
@@ -351,7 +352,7 @@ class Path:
         return io.TextIOWrapper(stream, encoding, *args, **kwargs)
 
     def _base(self):
-        return pathlib.PurePosixPath(self.at or self.root.filename)
+        return pathlib.PurePosixPath(self.at) if self.at else self.filename
 
     @property
     def name(self):
index 4320f1c0badcf91cd75811e32e721a588488b86c..4ed74cc48d9a91689280608f954e52150f5536f5 100644 (file)
@@ -1,7 +1,6 @@
 import os
 import re
 
-
 _default_seps = os.sep + str(os.altsep) * bool(os.altsep)
 
 
diff --git a/Misc/NEWS.d/next/Library/2025-06-08-14-50-34.gh-issue-135276.ZLUhV1.rst b/Misc/NEWS.d/next/Library/2025-06-08-14-50-34.gh-issue-135276.ZLUhV1.rst
new file mode 100644 (file)
index 0000000..e630b7d
--- /dev/null
@@ -0,0 +1,3 @@
+Backported bugfixes in zipfile.Path from zipp 3.23. Fixed
+``.name``, ``.stem`` and other basename-based properties on Windows when
+working with a zipfile on disk.