Repository: huggingface/datasets
File: tests/fixtures/fsspec.py (Python)

Code before:

    def makedirs(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.makedirs(path, *args, **kwargs)

    def rmdir(self, path):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.rmdir(path)

    def ls(self, path, detail=True, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        out = self._fs.ls(path, detail=detail, *args, **kwargs)
        if detail:
            return [{**info, "name": info["name"][len(self.local_root_dir) :]} for info in out]
        else:
            return [name[len(self.local_root_dir) :] for name in out]

    def info(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        out = dict(self._fs.info(path, *args, **kwargs))
        out["name"] = out["name"][len(self.local_root_dir) :]
        return out

    def get_file(self, rpath, lpath, *args, **kwargs):
        rpath = posixpath.join(self.local_root_dir, self._strip_protocol(rpath))
        return self._fs.get_file(rpath, lpath, *args, **kwargs)

    def cp_file(self, path1, path2, *args, **kwargs):
        path1 = posixpath.join(self.local_root_dir, self._strip_protocol(path1))
        path2 = posixpath.join(self.local_root_dir, self._strip_protocol(path2))
        return self._fs.cp_file(path1, path2, *args, **kwargs)

    def rm_file(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.rm_file(path, *args, **kwargs)

    def rm(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.rm(path, *args, **kwargs)

    def _open(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs._open(path, *args, **kwargs)

    def created(self, path):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.created(path)

    def modified(self, path):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.modified(path)

Review comment (refactor):
Why is it needed ? IIRC it's already implemented as part of the `AbstractFileSystem` and uses `self.open()` under the hood

Code after:
        return self._fs.mkdir(path, *args, **kwargs)

    def makedirs(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.makedirs(path, *args, **kwargs)

    def rmdir(self, path):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.rmdir(path)

    def ls(self, path, detail=True, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        out = self._fs.ls(path, detail=detail, *args, **kwargs)
        if detail:
            return [{**info, "name": info["name"][len(self.local_root_dir) :]} for info in out]
        else:
            return [name[len(self.local_root_dir) :] for name in out]

    def info(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        out = dict(self._fs.info(path, *args, **kwargs))
        out["name"] = out["name"][len(self.local_root_dir) :]
        return out

    def cp_file(self, path1, path2, *args, **kwargs):
        path1 = posixpath.join(self.local_root_dir, self._strip_protocol(path1))
        path2 = posixpath.join(self.local_root_dir, self._strip_protocol(path2))
        return self._fs.cp_file(path1, path2, *args, **kwargs)

    def rm_file(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.rm_file(path, *args, **kwargs)

    def rm(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.rm(path, *args, **kwargs)

    def _open(self, path, *args, **kwargs):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs._open(path, *args, **kwargs)

    def created(self, path):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.created(path)

    def modified(self, path):
        path = posixpath.join(self.local_root_dir, self._strip_protocol(path))
        return self._fs.modified(path)

    @classmethod
    def _strip_protocol(cls, path):