Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/442-excess-entries
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 9, 2023
2 parents 4c02b18 + 4df89f1 commit 64ae8f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
v6.1.1
v6.2.1
======

* #442: Fixed issue introduced in v6.1.0 where non-importable
names (metadata dirs) began appearing in
``packages_distributions``.

v6.2.0
======

* #384: ``PackageMetadata`` now stipulates an additional ``get``
method allowing for easy querying of metadata keys that may not
be present.

v6.1.0
======

Expand Down
8 changes: 8 additions & 0 deletions importlib_metadata/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def __getitem__(self, key: str) -> str:
def __iter__(self) -> Iterator[str]:
... # pragma: no cover

@overload
def get(self, name: str, failobj: None = None) -> Optional[str]:
... # pragma: no cover

@overload
def get(self, name: str, failobj: _T) -> Union[str, _T]:
... # pragma: no cover

# overload per python/importlib_metadata#435
@overload
def get_all(self, name: str, failobj: None = None) -> Optional[List[Any]]:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ def test_missing_key_legacy(self):
with suppress_known_deprecation():
assert md['does-not-exist'] is None

def test_get_key(self):
"""
Getting a key gets the key.
"""
md = metadata('egginfo-pkg')
assert md.get('Name') == 'egginfo-pkg'

def test_get_missing_key(self):
"""
Requesting a missing key will return None.
"""
md = metadata('distinfo-pkg')
assert md.get('does-not-exist') is None

@staticmethod
def _test_files(files):
root = files[0].root
Expand Down

0 comments on commit 64ae8f6

Please sign in to comment.