Skip to content

Commit 5ca5fd8

Browse files
committed
Extend PackageMetadata protocol to include the requisite interface, including some way to iterate over the keys and the new json property.
1 parent b9ce1b1 commit 5ca5fd8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

importlib_metadata/_adapters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def __new__(cls, orig: email.message.Message):
1313
def __init__(self, *args, **kwargs):
1414
pass
1515

16+
# suppress spurious error from mypy
17+
def __iter__(self):
18+
return super().__iter__()
19+
1620
@property
1721
def json(self):
1822
"""

importlib_metadata/_meta.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ._compat import Protocol
2-
from typing import Any, List, TypeVar, Union
2+
from typing import Any, Dict, Iterator, List, TypeVar, Union
33

44

55
_T = TypeVar("_T")
@@ -15,10 +15,19 @@ def __contains__(self, item: str) -> bool:
1515
def __getitem__(self, key: str) -> str:
1616
... # pragma: no cover
1717

18+
def __iter__(self) -> Iterator[str]:
19+
... # pragma: no cover
20+
1821
def get_payload(self) -> str:
1922
... # pragma: no cover
2023

2124
def get_all(self, name: str, failobj: _T = ...) -> Union[List[Any], _T]:
2225
"""
2326
Return all values associated with a possibly multi-valued key.
2427
"""
28+
29+
@property
30+
def json(self) -> Dict[str, Union[str, List[str]]]:
31+
"""
32+
A JSON-compatible form of the metadata.
33+
"""

0 commit comments

Comments
 (0)