From 0c1d32e2656ac7ebc6fcc4377345f9909c9b7fbc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Dec 2023 13:28:04 -0500 Subject: [PATCH] Inline os.PathLike using future annotations. --- importlib_metadata/__init__.py | 11 ++++++----- importlib_metadata/_compat.py | 10 ---------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 6108dbc3..02c799d1 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import re import abc @@ -21,7 +23,6 @@ from ._collections import FreezableDefaultDict, Pair from ._compat import ( NullFinder, - StrPath, install, ) from ._functools import method_cache, pass_none @@ -387,7 +388,7 @@ def read_text(self, filename) -> Optional[str]: """ @abc.abstractmethod - def locate_file(self, path: StrPath) -> SimplePath: + def locate_file(self, path: os.PathLike[str]) -> SimplePath: """ Given a path to a file in this distribution, return a SimplePath to it. @@ -432,7 +433,7 @@ def discover( ) @staticmethod - def at(path: StrPath) -> "Distribution": + def at(path: os.PathLike[str]) -> "Distribution": """Return a Distribution for the indicated metadata path. :param path: a string or path-like object @@ -840,7 +841,7 @@ def __init__(self, path: SimplePath) -> None: """ self._path = path - def read_text(self, filename: StrPath) -> Optional[str]: + def read_text(self, filename: os.PathLike[str]) -> Optional[str]: with suppress( FileNotFoundError, IsADirectoryError, @@ -854,7 +855,7 @@ def read_text(self, filename: StrPath) -> Optional[str]: read_text.__doc__ = Distribution.read_text.__doc__ - def locate_file(self, path: StrPath) -> SimplePath: + def locate_file(self, path: os.PathLike[str]) -> SimplePath: return self._path.parent / path @property diff --git a/importlib_metadata/_compat.py b/importlib_metadata/_compat.py index f444c341..df312b1c 100644 --- a/importlib_metadata/_compat.py +++ b/importlib_metadata/_compat.py @@ -1,9 +1,6 @@ -import os import sys import platform -from typing import Union - __all__ = ['install', 'NullFinder'] @@ -58,10 +55,3 @@ def pypy_partial(val): """ is_pypy = platform.python_implementation() == 'PyPy' return val + is_pypy - - -if sys.version_info >= (3, 9): - StrPath = Union[str, os.PathLike[str]] -else: - # PathLike is only subscriptable at runtime in 3.9+ - StrPath = Union[str, "os.PathLike[str]"] # pragma: no cover