Skip to content

Commit

Permalink
Use __contains__ to avoid KeyError with importlib_metadata==8.0.0 (
Browse files Browse the repository at this point in the history
…#384)

We don't actually depend on the backport, but a pytest plugin that we
are using, pytest-console-scripts, does.

importlib_metadata==8.0.0 now raises a KeyError when we try to get
metadata that doesn't exist (where before it would return None).

When running the automated tests, we would fail because the backport
would for some reason take precedence over the stdlib. To resolve this,
the current impl is replaced with a __contains__() call.
  • Loading branch information
kemzeb authored Jun 26, 2024
1 parent 8c56559 commit 5eabebe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/pipdeptree/_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def filter_valid_distributions(iterable_dists: Iterable[Distribution]) -> list[D


def has_valid_metadata(dist: Distribution) -> bool:
return dist.metadata["Name"] is not None
return "Name" in dist.metadata


def render_invalid_metadata_text(site_dirs_with_invalid_metadata: set[str]) -> None:
Expand Down

0 comments on commit 5eabebe

Please # to comment.