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

@@ -68,12 +68,6 @@ doctest.TestResults.__new__
email.utils.getaddresses
email.utils.parseaddr
filecmp.dircmp.__init__
importlib.metadata.DeprecatedTuple
importlib.metadata.Distribution.origin
importlib.metadata._meta.SimplePath.exists
importlib.metadata._meta.SimplePath.read_bytes
importlib.metadata._meta.SimplePath.read_text
importlib.metadata.diagnose
importlib.resources.Anchor
importlib.resources.Resource
importlib.resources.__all__

View File

@@ -4,7 +4,6 @@ import sys
from _typeshed import StrPath
from os import PathLike
from pathlib import Path
from typing import Any
from zipfile import Path as ZipPath
if sys.version_info >= (3, 10):
@@ -16,16 +15,12 @@ if sys.version_info >= (3, 10):
def parent(self) -> PathLike[str]: ... # undocumented
def read_text(self, encoding: str | None = ..., errors: str | None = ...) -> str: ...
def read_bytes(self) -> bytes: ...
def joinpath(self, *other: StrPath) -> MyPath: ...
def __truediv__(self, add: StrPath) -> MyPath: ...
def exists(self) -> bool: ...
if sys.version_info >= (3, 12):
def takes_simple_path(p: SimplePath[Any]) -> None: ...
else:
def takes_simple_path(p: SimplePath) -> None: ...
def takes_simple_path(p: SimplePath) -> None: ...
takes_simple_path(Path())
takes_simple_path(ZipPath(""))

View File

@@ -158,6 +158,7 @@ importlib: 3.0-
importlib._abc: 3.10-
importlib.metadata: 3.8-
importlib.metadata._meta: 3.10-
importlib.metadata.diagnose: 3.13-
importlib.readers: 3.10-
importlib.resources: 3.7-
importlib.resources.abc: 3.11-

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: ...