Resolve importlib.metadata 3.13 issues (#12299)

This commit is contained in:
Max Muoto
2024-07-11 19:04:55 -05:00
committed by GitHub
parent eb0422195e
commit 08c44b7895
6 changed files with 32 additions and 23 deletions

View File

@@ -1,6 +1,7 @@
import abc
import pathlib
import sys
import types
from _collections_abc import dict_keys, dict_values
from _typeshed import StrPath
from collections.abc import Iterable, Iterator, Mapping
@@ -36,11 +37,8 @@ if sys.version_info >= (3, 10):
from importlib.metadata._meta import PackageMetadata as PackageMetadata, SimplePath
def packages_distributions() -> Mapping[str, list[str]]: ...
if sys.version_info >= (3, 12):
# It's generic but shouldn't be
_SimplePath: TypeAlias = SimplePath[Any]
else:
_SimplePath: TypeAlias = SimplePath
_SimplePath: TypeAlias = SimplePath
else:
_SimplePath: TypeAlias = Path
@@ -48,7 +46,9 @@ class PackageNotFoundError(ModuleNotFoundError):
@property
def name(self) -> str: ... # type: ignore[override]
if sys.version_info >= (3, 11):
if sys.version_info >= (3, 13):
_EntryPointBase = object
elif sys.version_info >= (3, 11):
class DeprecatedTuple:
def __getitem__(self, item: int) -> str: ...
@@ -226,6 +226,9 @@ class Distribution(_distribution_parent):
if sys.version_info >= (3, 10):
@property
def name(self) -> str: ...
if sys.version_info >= (3, 13):
@property
def origin(self) -> types.SimpleNamespace: ...
class DistributionFinder(MetaPathFinder):
class Context:

View File

@@ -1,9 +1,12 @@
import sys
from _typeshed import StrPath
from collections.abc import Iterator
from typing import Any, Protocol, TypeVar, overload
from os import PathLike
from typing import Any, Protocol, overload
from typing_extensions import TypeVar
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T_co = TypeVar("_T_co", covariant=True, default=Any)
class PackageMetadata(Protocol):
def __len__(self) -> int: ...
@@ -22,7 +25,18 @@ class PackageMetadata(Protocol):
@overload
def get(self, name: str, failobj: _T) -> _T | str: ...
if sys.version_info >= (3, 12):
if sys.version_info >= (3, 13):
class SimplePath(Protocol):
def joinpath(self, other: StrPath, /) -> SimplePath: ...
def __truediv__(self, other: StrPath, /) -> SimplePath: ...
# Incorrect at runtime
@property
def parent(self) -> PathLike[str]: ...
def read_text(self, encoding: str | None = None) -> str: ...
def read_bytes(self) -> bytes: ...
def exists(self) -> bool: ...
elif sys.version_info >= (3, 12):
class SimplePath(Protocol[_T_co]):
# At runtime this is defined as taking `str | _T`, but that causes trouble.
# See #11436.

View File

@@ -0,0 +1,2 @@
def inspect(path: str) -> None: ...
def run() -> None: ...