Skip to content

Commit f4b43da

Browse files
Update importlib.metadata typings for 3.10 (#7331)
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
1 parent a342a49 commit f4b43da

File tree

1 file changed

+77
-8
lines changed

1 file changed

+77
-8
lines changed

stdlib/importlib/metadata/__init__.pyi

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import abc
22
import pathlib
33
import sys
4-
from _typeshed import StrPath
4+
from _typeshed import Self, StrPath
55
from collections.abc import Mapping
66
from email.message import Message
77
from importlib.abc import MetaPathFinder
@@ -61,7 +61,56 @@ class EntryPoint(_EntryPointBase):
6161
def attr(self) -> str: ...
6262
if sys.version_info >= (3, 10):
6363
dist: ClassVar[Distribution | None]
64-
def matches(self, **params: Any) -> bool: ... # undocumented
64+
def matches(
65+
self,
66+
*,
67+
name: str = ...,
68+
value: str = ...,
69+
group: str = ...,
70+
module: str = ...,
71+
attr: str = ...,
72+
extras: list[str] = ...,
73+
) -> bool: ... # undocumented
74+
75+
if sys.version_info >= (3, 10):
76+
class EntryPoints(list[EntryPoint]): # use as list is deprecated since 3.10
77+
# int argument is deprecated since 3.10
78+
def __getitem__(self, item: int | str) -> EntryPoint: ... # type: ignore[override]
79+
def select(
80+
self,
81+
*,
82+
name: str = ...,
83+
value: str = ...,
84+
group: str = ...,
85+
module: str = ...,
86+
attr: str = ...,
87+
extras: list[str] = ...,
88+
) -> EntryPoints: ...
89+
@property
90+
def names(self) -> set[str]: ...
91+
@property
92+
def groups(self) -> set[str]: ...
93+
94+
class SelectableGroups(dict[str, EntryPoints]): # use as dict is deprecated since 3.10
95+
@classmethod
96+
def load(cls: type[Self], eps: Iterable[EntryPoint]) -> Self: ...
97+
@property
98+
def groups(self) -> set[str]: ...
99+
@property
100+
def names(self) -> set[str]: ...
101+
@overload
102+
def select(self: Self) -> Self: ... # type: ignore[misc]
103+
@overload
104+
def select(
105+
self,
106+
*,
107+
name: str = ...,
108+
value: str = ...,
109+
group: str = ...,
110+
module: str = ...,
111+
attr: str = ...,
112+
extras: list[str] = ...,
113+
) -> EntryPoints: ...
65114

66115
class PackagePath(pathlib.PurePosixPath):
67116
def read_text(self, encoding: str = ...) -> str: ...
@@ -94,13 +143,21 @@ class Distribution:
94143
) -> Iterable[Distribution]: ...
95144
@staticmethod
96145
def at(path: StrPath) -> PathDistribution: ...
97-
@property
98-
def metadata(self) -> Message: ...
146+
147+
if sys.version_info >= (3, 10):
148+
@property
149+
def metadata(self) -> PackageMetadata: ...
150+
@property
151+
def entry_points(self) -> EntryPoints: ...
152+
else:
153+
@property
154+
def metadata(self) -> Message: ...
155+
@property
156+
def entry_points(self) -> list[EntryPoint]: ...
157+
99158
@property
100159
def version(self) -> str: ...
101160
@property
102-
def entry_points(self) -> list[EntryPoint]: ...
103-
@property
104161
def files(self) -> list[PackagePath] | None: ...
105162
@property
106163
def requires(self) -> list[str] | None: ...
@@ -137,8 +194,20 @@ def distributions(*, context: DistributionFinder.Context) -> Iterable[Distributi
137194
def distributions(
138195
*, context: None = ..., name: str | None = ..., path: list[str] = ..., **kwargs: Any
139196
) -> Iterable[Distribution]: ...
140-
def metadata(distribution_name: str) -> Message: ...
197+
198+
if sys.version_info >= (3, 10):
199+
def metadata(distribution_name: str) -> PackageMetadata: ...
200+
@overload
201+
def entry_points() -> SelectableGroups: ... # type: ignore[misc]
202+
@overload
203+
def entry_points(
204+
*, name: str = ..., value: str = ..., group: str = ..., module: str = ..., attr: str = ..., extras: list[str] = ...
205+
) -> EntryPoints: ...
206+
207+
else:
208+
def metadata(distribution_name: str) -> Message: ...
209+
def entry_points() -> dict[str, list[EntryPoint]]: ...
210+
141211
def version(distribution_name: str) -> str: ...
142-
def entry_points() -> dict[str, tuple[EntryPoint, ...]]: ...
143212
def files(distribution_name: str) -> list[PackagePath] | None: ...
144213
def requires(distribution_name: str) -> list[str] | None: ...

0 commit comments

Comments
 (0)