From 5eabebe1141073b64862cc238c09f9d03f225611 Mon Sep 17 00:00:00 2001 From: Kemal Zebari <60799661+kemzeb@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:34:41 -0700 Subject: [PATCH] Use `__contains__` to avoid `KeyError` with importlib_metadata==8.0.0 (#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. --- src/pipdeptree/_discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipdeptree/_discovery.py b/src/pipdeptree/_discovery.py index 5507b61..09e290c 100644 --- a/src/pipdeptree/_discovery.py +++ b/src/pipdeptree/_discovery.py @@ -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: