|
16 | 16 | NullFinder, |
17 | 17 | PyPy_repr, |
18 | 18 | install, |
| 19 | + Protocol, |
19 | 20 | ) |
20 | 21 |
|
21 | 22 | from configparser import ConfigParser |
22 | 23 | from contextlib import suppress |
23 | 24 | from importlib import import_module |
24 | 25 | from importlib.abc import MetaPathFinder |
25 | 26 | from itertools import starmap |
26 | | -from typing import Optional |
| 27 | +from typing import Any, List, Optional, TypeVar, Union |
27 | 28 |
|
28 | 29 |
|
29 | 30 | __all__ = [ |
@@ -172,6 +173,25 @@ def __repr__(self): |
172 | 173 | return '<FileHash mode: {} value: {}>'.format(self.mode, self.value) |
173 | 174 |
|
174 | 175 |
|
| 176 | +_T = TypeVar("_T") |
| 177 | + |
| 178 | + |
| 179 | +class PackageMetadata(Protocol): |
| 180 | + def __len__(self) -> int: |
| 181 | + ... # pragma: no cover |
| 182 | + |
| 183 | + def __contains__(self, item: str) -> bool: |
| 184 | + ... # pragma: no cover |
| 185 | + |
| 186 | + def __getitem__(self, key: str) -> str: |
| 187 | + ... # pragma: no cover |
| 188 | + |
| 189 | + def get_all(self, name: str, failobj: _T = ...) -> Union[List[Any], _T]: |
| 190 | + """ |
| 191 | + Return all values associated with a possibly multi-valued key. |
| 192 | + """ |
| 193 | + |
| 194 | + |
175 | 195 | class Distribution: |
176 | 196 | """A Python distribution package.""" |
177 | 197 |
|
@@ -256,7 +276,7 @@ def _local(cls, root='.'): |
256 | 276 | return PathDistribution(zipp.Path(meta.build_as_zip(builder))) |
257 | 277 |
|
258 | 278 | @property |
259 | | - def metadata(self): |
| 279 | + def metadata(self) -> PackageMetadata: |
260 | 280 | """Return the parsed metadata for this Distribution. |
261 | 281 |
|
262 | 282 | The returned object will have keys that name the various bits of |
@@ -592,11 +612,11 @@ def distributions(**kwargs): |
592 | 612 | return Distribution.discover(**kwargs) |
593 | 613 |
|
594 | 614 |
|
595 | | -def metadata(distribution_name): |
| 615 | +def metadata(distribution_name) -> PackageMetadata: |
596 | 616 | """Get the metadata for the named package. |
597 | 617 |
|
598 | 618 | :param distribution_name: The name of the distribution package to query. |
599 | | - :return: An email.Message containing the parsed metadata. |
| 619 | + :return: A PackageMetadata containing the parsed metadata. |
600 | 620 | """ |
601 | 621 | return Distribution.from_name(distribution_name).metadata |
602 | 622 |
|
|
0 commit comments