|
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 |
| 27 | +from typing import Any, List, TypeVar, Union |
26 | 28 |
|
27 | 29 |
|
28 | 30 | __all__ = [ |
@@ -161,6 +163,25 @@ def __repr__(self): |
161 | 163 | return '<FileHash mode: {} value: {}>'.format(self.mode, self.value) |
162 | 164 |
|
163 | 165 |
|
| 166 | +_T = TypeVar("_T") |
| 167 | + |
| 168 | + |
| 169 | +class PackageMetadata(Protocol): |
| 170 | + def __len__(self) -> int: |
| 171 | + ... # pragma: no cover |
| 172 | + |
| 173 | + def __contains__(self, item: str) -> bool: |
| 174 | + ... # pragma: no cover |
| 175 | + |
| 176 | + def __getitem__(self, key: str) -> str: |
| 177 | + ... # pragma: no cover |
| 178 | + |
| 179 | + def get_all(self, name: str, failobj: _T = ...) -> Union[List[Any], _T]: |
| 180 | + """ |
| 181 | + Return all values associated with a possibly multi-valued key. |
| 182 | + """ |
| 183 | + |
| 184 | + |
164 | 185 | class Distribution: |
165 | 186 | """A Python distribution package.""" |
166 | 187 |
|
@@ -245,7 +266,7 @@ def _local(cls, root='.'): |
245 | 266 | return PathDistribution(zipp.Path(meta.build_as_zip(builder))) |
246 | 267 |
|
247 | 268 | @property |
248 | | - def metadata(self): |
| 269 | + def metadata(self) -> PackageMetadata: |
249 | 270 | """Return the parsed metadata for this Distribution. |
250 | 271 |
|
251 | 272 | The returned object will have keys that name the various bits of |
@@ -576,11 +597,11 @@ def distributions(**kwargs): |
576 | 597 | return Distribution.discover(**kwargs) |
577 | 598 |
|
578 | 599 |
|
579 | | -def metadata(distribution_name): |
| 600 | +def metadata(distribution_name) -> PackageMetadata: |
580 | 601 | """Get the metadata for the named package. |
581 | 602 |
|
582 | 603 | :param distribution_name: The name of the distribution package to query. |
583 | | - :return: An email.Message containing the parsed metadata. |
| 604 | + :return: A PackageMetadata containing the parsed metadata. |
584 | 605 | """ |
585 | 606 | return Distribution.from_name(distribution_name).metadata |
586 | 607 |
|
|
0 commit comments