From 4afd82d8dd2c1ef48c62bdf875a194e407f2d2d3 Mon Sep 17 00:00:00 2001 From: Wei Yang Date: Sat, 10 Oct 2020 12:56:06 +0200 Subject: [PATCH] MAINT: py3k: remove os.fspath and os.PathLike backports (#17473) Since we no longer support Python 3.5 and below, this code is unreachable. As with the rest of `py3k.py`, we leave behind the aliases to prevent breaking downstream code. --- numpy/compat/py3k.py | 53 ++------------------------------------------ 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/numpy/compat/py3k.py b/numpy/compat/py3k.py index fd9f8bd4217e..5e742bf6cf29 100644 --- a/numpy/compat/py3k.py +++ b/numpy/compat/py3k.py @@ -133,54 +133,5 @@ def npy_load_module(name, fn, info=None): # Backport os.fs_path, os.PathLike, and PurePath.__fspath__ -if sys.version_info[:2] >= (3, 6): - os_fspath = os.fspath - os_PathLike = os.PathLike -else: - def _PurePath__fspath__(self): - return str(self) - - class os_PathLike(abc_ABC): - """Abstract base class for implementing the file system path protocol.""" - - @abc.abstractmethod - def __fspath__(self): - """Return the file system path representation of the object.""" - raise NotImplementedError - - @classmethod - def __subclasshook__(cls, subclass): - if PurePath is not None and issubclass(subclass, PurePath): - return True - return hasattr(subclass, '__fspath__') - - - def os_fspath(path): - """Return the path representation of a path-like object. - If str or bytes is passed in, it is returned unchanged. Otherwise the - os.PathLike interface is used to get the path representation. If the - path representation is not str or bytes, TypeError is raised. If the - provided path is not str, bytes, or os.PathLike, TypeError is raised. - """ - if isinstance(path, (str, bytes)): - return path - - # Work from the object's type to match method resolution of other magic - # methods. - path_type = type(path) - try: - path_repr = path_type.__fspath__(path) - except AttributeError: - if hasattr(path_type, '__fspath__'): - raise - elif PurePath is not None and issubclass(path_type, PurePath): - return _PurePath__fspath__(path) - else: - raise TypeError("expected str, bytes or os.PathLike object, " - "not " + path_type.__name__) - if isinstance(path_repr, (str, bytes)): - return path_repr - else: - raise TypeError("expected {}.__fspath__() to return str or bytes, " - "not {}".format(path_type.__name__, - type(path_repr).__name__)) +os_fspath = os.fspath +os_PathLike = os.PathLike