fsspec / filesystem_spec

A specification that python filesystems should adhere to.
BSD 3-Clause "New" or "Revised" License
997 stars 353 forks source link

Zip tests fail on Python 3.13 #1688

Open QuLogic opened 3 hours ago

QuLogic commented 3 hours ago

With Python 3.13, 8 tests in test_zip.py fail:

FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_detail_true
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_detail_false
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_detail_true_include_dirs
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_detail_false_include_dirs
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_path_set
FAILED fsspec/implementations/tests/test_zip.py::test_find_with_and_without_slash_should_return_same_result
FAILED fsspec/implementations/tests/test_zip.py::test_find_should_return_file_if_exact_match
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_recursion_depth_set

and they are all similar to:

________________ test_find_returns_expected_result_detail_true _________________
zip_file = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/test_find_returns_expected_res0/test.zip')
    def test_find_returns_expected_result_detail_true(zip_file):
>       zip_file_system = ZipFileSystem(zip_file)
fsspec/implementations/tests/test_zip.py:182: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
fsspec/spec.py:81: in __call__
    obj = super().__call__(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <Archive-like object ZipFileSystem at 139926732063376>
fo = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/test_find_returns_expected_res0/test.zip')
mode = 'r', target_protocol = None, target_options = None, compression = 0
allowZip64 = True, compresslevel = None, kwargs = {}
    def __init__(
        self,
        fo="",
        mode="r",
        target_protocol=None,
        target_options=None,
        compression=zipfile.ZIP_STORED,
        allowZip64=True,
        compresslevel=None,
        **kwargs,
    ):
        """
        Parameters
        ----------
        fo: str or file-like
            Contains ZIP, and must exist. If a str, will fetch file using
            :meth:`~fsspec.open_files`, which must return one file exactly.
        mode: str
            Accept: "r", "w", "a"
        target_protocol: str (optional)
            If ``fo`` is a string, this value can be used to override the
            FS protocol inferred from a URL
        target_options: dict (optional)
            Kwargs passed when instantiating the target FS, if ``fo`` is
            a string.
        compression, allowZip64, compresslevel: passed to ZipFile
            Only relevant when creating a ZIP
        """
        super().__init__(self, **kwargs)
        if mode not in set("rwa"):
            raise ValueError(f"mode '{mode}' no understood")
        self.mode = mode
        if isinstance(fo, str):
            if mode == "a":
                m = "r+b"
            else:
                m = mode + "b"
            fo = fsspec.open(
                fo, mode=m, protocol=target_protocol, **(target_options or {})
            )
        self.force_zip_64 = allowZip64
        self.of = fo
>       self.fo = fo.__enter__()  # the whole instance is a context
E       AttributeError: 'PosixPath' object has no attribute '__enter__'. Did you mean: '__bytes__'?
fsspec/implementations/zip.py:61: AttributeError
QuLogic commented 2 hours ago

I just noticed this warning on Python 3.12:

filesystem_spec/fsspec/implementations/zip.py:61: DeprecationWarning: pathlib.Path.__enter__() is deprecated and scheduled for removal in Python 3.13; Path objects as a context manager is a no-op
    self.fo = fo.__enter__()  # the whole instance is a context