diff --git a/satpy/readers/__init__.py b/satpy/readers/__init__.py index 3c0f788aab..6cb6327d6f 100644 --- a/satpy/readers/__init__.py +++ b/satpy/readers/__init__.py @@ -546,8 +546,14 @@ class FSFile(os.PathLike): def __init__(self, file, fs=None): """Initialise the FSFile instance. - *file* can be string or an fsspec.OpenFile instance. In the latter case, the follow argument *fs* has no effect. - *fs* can be None or a fsspec filesystem instance. + Args: + file (str, Pathlike, or OpenFile): + String, object implementing the `os.PathLike` protocol, or + an `fsspec.OpenFile` instance. If passed an instance of + `fsspec.OpenFile`, the following argument ``fs`` has no + effect. + fs (fsspec filesystem, optional) + Object implementing the fsspec filesystem protocol. """ try: self._file = file.path @@ -558,11 +564,11 @@ def __init__(self, file, fs=None): def __str__(self): """Return the string version of the filename.""" - return self._file + return os.fspath(self._file) def __fspath__(self): """Comply with PathLike.""" - return self._file + return os.fspath(self._file) def __repr__(self): """Representation of the object.""" diff --git a/satpy/tests/test_readers.py b/satpy/tests/test_readers.py index ec28b6aff0..f6b84b3a2e 100644 --- a/satpy/tests/test_readers.py +++ b/satpy/tests/test_readers.py @@ -896,6 +896,12 @@ def test_fsfile_with_regular_filename_and_fs_spec_abides_pathlike(self): from satpy.readers import FSFile assert os.fspath(FSFile(self.random_string, fs=None)) == self.random_string + def test_fsfile_with_pathlike(self): + from satpy.readers import FSFile + from pathlib import Path + f = FSFile(Path(self.local_filename)) + assert str(f) == os.fspath(f) == self.local_filename + def test_fsfile_with_fs_open_file_abides_pathlike(self): """Test that FSFile abides PathLike for fsspec OpenFile instances.""" from satpy.readers import FSFile