os.PathLike is >=py36
-import os
import sys
from contextlib import contextmanager
+try:
+ from os import PathLike
+except ImportError:
+ from pathlib import PurePath as PathLike
+
def is_buffer(obj, mode):
return ("r" in mode and hasattr(obj, "read")) or (
@@ -13,7 +17,7 @@ def is_buffer(obj, mode):
def open_file(path_or_buf, mode="r"):
if is_buffer(path_or_buf, mode):
yield path_or_buf
- elif sys.version_info < (3, 6) and isinstance(path_or_buf, os.PathLike):
+ elif sys.version_info < (3, 6) and isinstance(path_or_buf, PathLike):
# TODO remove when python 3.5 is EoL (i.e. 2020-09-13)
# https://devguide.python.org/#status-of-python-branches
# https://www.python.org/dev/peps/pep-0478/
