Skip to content

Commit

Permalink
fix issue where open_file_or_filename tries to open pathlib path
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-rdz committed Sep 12, 2023
1 parent 99e7df6 commit ed9948f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions satpy/readers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
import pickle # nosec B403
import warnings
import pathlib
from datetime import datetime, timedelta
from functools import total_ordering

Expand Down Expand Up @@ -779,8 +780,11 @@ def _get_compression(file):

def open_file_or_filename(unknown_file_thing):
"""Try to open the *unknown_file_thing*, otherwise return the filename."""
try:
f_obj = unknown_file_thing.open()
except AttributeError:
if isinstance(unknown_file_thing, (pathlib.WindowsPath, pathlib.PosixPath)):
f_obj = unknown_file_thing
else:
try:
f_obj = unknown_file_thing.open()
except AttributeError:
f_obj = unknown_file_thing
return f_obj

0 comments on commit ed9948f

Please sign in to comment.