From b99c9d6680e549bb232bfe2ee9c6a4bd74874c32 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Dec 2023 13:17:56 -0500 Subject: [PATCH] Refine SimplePath to allow for os.PathLike on input and SimplePath on output. --- docs/conf.py | 2 -- importlib_metadata/_meta.py | 11 +++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 70e5c2dd..134d7534 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -71,6 +71,4 @@ ('py:class', '_T'), # Other workarounds ('py:class', 'importlib_metadata.DeprecatedNonAbstract'), - # Workaround needed for #480 - ('py:obj', 'importlib_metadata._meta._T'), ] diff --git a/importlib_metadata/_meta.py b/importlib_metadata/_meta.py index be30c15e..1342d839 100644 --- a/importlib_metadata/_meta.py +++ b/importlib_metadata/_meta.py @@ -1,3 +1,6 @@ +from __future__ import annotations + +import os from typing import Protocol from typing import Any, Dict, Iterator, List, Optional, TypeVar, Union, overload @@ -44,19 +47,19 @@ def json(self) -> Dict[str, Union[str, List[str]]]: """ -class SimplePath(Protocol[_T]): +class SimplePath(Protocol): """ A minimal subset of pathlib.Path required by Distribution. """ - def joinpath(self, other: Union[str, _T]) -> _T: + def joinpath(self, other: Union[str, os.PathLike[str]]) -> SimplePath: ... # pragma: no cover - def __truediv__(self, other: Union[str, _T]) -> _T: + def __truediv__(self, other: Union[str, os.PathLike[str]]) -> SimplePath: ... # pragma: no cover @property - def parent(self) -> _T: + def parent(self) -> SimplePath: ... # pragma: no cover def read_text(self, encoding=None) -> str: