Skip to content

Commit c19a2d0

Browse files
committed
Merge branch 'main' into bugfix/bpo-42382
2 parents c5dbfdb + 877d351 commit c19a2d0

File tree

7 files changed

+79
-11
lines changed

7 files changed

+79
-11
lines changed

.github/workflows/automerge.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: automerge
2+
on:
3+
pull_request:
4+
types:
5+
- labeled
6+
- unlabeled
7+
- synchronize
8+
- opened
9+
- edited
10+
- ready_for_review
11+
- reopened
12+
- unlocked
13+
pull_request_review:
14+
types:
15+
- submitted
16+
check_suite:
17+
types:
18+
- completed
19+
status: {}
20+
jobs:
21+
automerge:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: automerge
25+
uses: "pascalgn/[email protected]"
26+
env:
27+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

CHANGES.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
v3.2.0
1+
v3.3.0
22
======
33

4-
* #265: ``EntryPoint`` objects now expose a ``.dist`` object
4+
* * #265: ``EntryPoint`` objects now expose a ``.dist`` object
55
referencing the ``Distribution`` when constructed from a
66
Distribution.
77

8+
v3.2.0
9+
======
10+
11+
* The object returned by ``metadata()`` now has a
12+
formally-defined protocol called ``PackageMetadata``
13+
with declared support for the ``.get_all()`` method.
14+
Fixes #126.
15+
816
v3.1.1
917
======
1018

docs/using.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ Every distribution includes some metadata, which you can extract using the
108108

109109
>>> wheel_metadata = metadata('wheel')
110110

111-
The keys of the returned data structure [#f1]_ name the metadata keywords, and
112-
their values are returned unparsed from the distribution metadata::
111+
The keys of the returned data structure, a ``PackageMetadata``,
112+
name the metadata keywords, and
113+
the values are returned unparsed from the distribution metadata::
113114

114115
>>> wheel_metadata['Requires-Python']
115116
'>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*'

importlib_metadata/__init__.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
NullFinder,
1717
PyPy_repr,
1818
install,
19+
Protocol,
1920
)
2021

2122
from configparser import ConfigParser
2223
from contextlib import suppress
2324
from importlib import import_module
2425
from importlib.abc import MetaPathFinder
2526
from itertools import starmap
26-
from typing import Optional
27+
from typing import Any, List, Optional, TypeVar, Union
2728

2829

2930
__all__ = [
@@ -172,6 +173,25 @@ def __repr__(self):
172173
return '<FileHash mode: {} value: {}>'.format(self.mode, self.value)
173174

174175

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+
175195
class Distribution:
176196
"""A Python distribution package."""
177197

@@ -256,7 +276,7 @@ def _local(cls, root='.'):
256276
return PathDistribution(zipp.Path(meta.build_as_zip(builder)))
257277

258278
@property
259-
def metadata(self):
279+
def metadata(self) -> PackageMetadata:
260280
"""Return the parsed metadata for this Distribution.
261281
262282
The returned object will have keys that name the various bits of
@@ -592,11 +612,11 @@ def distributions(**kwargs):
592612
return Distribution.discover(**kwargs)
593613

594614

595-
def metadata(distribution_name):
615+
def metadata(distribution_name) -> PackageMetadata:
596616
"""Get the metadata for the named package.
597617
598618
: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.
600620
"""
601621
return Distribution.from_name(distribution_name).metadata
602622

importlib_metadata/_compat.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import sys
22

33

4-
__all__ = ['install', 'NullFinder', 'PyPy_repr']
4+
__all__ = ['install', 'NullFinder', 'PyPy_repr', 'Protocol']
5+
6+
7+
try:
8+
from typing import Protocol
9+
except ImportError: # pragma: no cover
10+
"""
11+
pytest-mypy complains here because:
12+
error: Incompatible import of "Protocol" (imported name has type
13+
"typing_extensions._SpecialForm", local name has type "typing._SpecialForm")
14+
"""
15+
from typing_extensions import Protocol # type: ignore
516

617

718
def install(cls):

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ include_package_data = true
1919
python_requires = >=3.6
2020
install_requires =
2121
zipp>=0.5
22+
typing-extensions>=3.6.4; python_version < "3.8"
2223
setup_requires = setuptools_scm[toml] >= 3.4.1
2324

2425
[options.packages.find]

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ deps =
2626
diff-cover
2727
commands =
2828
pytest {posargs} --cov-report xml
29-
diff-cover coverage.xml --html-report diffcov.html
30-
diff-cover coverage.xml --fail-under=100
29+
diff-cover coverage.xml --compare-branch=origin/main --html-report diffcov.html
30+
diff-cover coverage.xml --compare-branch=origin/main --fail-under=100
3131

3232
[testenv:perf]
3333
use_develop = False

0 commit comments

Comments
 (0)