summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei Yang <wyang_92@Hotmail.com>2020-10-10 12:56:06 +0200
committerGitHub <noreply@github.com>2020-10-10 11:56:06 +0100
commit4afd82d8dd2c1ef48c62bdf875a194e407f2d2d3 (patch)
treedcd56ac2b81c76837a2605e085c57550521714d2
parentaeb23741b1186e6ae525c4dd7f46ce9e1378e670 (diff)
downloadnumpy-4afd82d8dd2c1ef48c62bdf875a194e407f2d2d3.tar.gz
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.
-rw-r--r--numpy/compat/py3k.py53
1 files changed, 2 insertions, 51 deletions
diff --git a/numpy/compat/py3k.py b/numpy/compat/py3k.py
index fd9f8bd42..5e742bf6c 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