Skip to content

Commit c227e11

Browse files
authored
ref(utils): Explicitly use None default when checking metadata (#4039)
Fixes #4035 As described in the above issue, starting in Python 3.14 importlib_metadata 8 provides the desired behavior, raising KeyError on a missing key. In preparation for this change, and to remove a DeprecationWarning, we should explicitly default to None when getting metadata.
1 parent d937272 commit c227e11

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sentry_sdk/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ def _generate_installed_modules():
16651665

16661666
yielded = set()
16671667
for dist in metadata.distributions():
1668-
name = dist.metadata["Name"]
1668+
name = dist.metadata.get("Name", None) # type: ignore[attr-defined]
16691669
# `metadata` values may be `None`, see:
16701670
# https://github.com/python/cpython/issues/91216
16711671
# and

tests/test_utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,12 @@ def test_installed_modules():
650650

651651
if importlib_available:
652652
importlib_distributions = {
653-
_normalize_distribution_name(dist.metadata["Name"]): version(
654-
dist.metadata["Name"]
653+
_normalize_distribution_name(dist.metadata.get("Name", None)): version(
654+
dist.metadata.get("Name", None)
655655
)
656656
for dist in distributions()
657-
if dist.metadata["Name"] is not None
658-
and version(dist.metadata["Name"]) is not None
657+
if dist.metadata.get("Name", None) is not None
658+
and version(dist.metadata.get("Name", None)) is not None
659659
}
660660
assert installed_distributions == importlib_distributions
661661

0 commit comments

Comments
 (0)