Skip to content

Commit b8351fd

Browse files
authored
Added type hints to map_metadata_keys() (#9337)
1 parent 5258422 commit b8351fd

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Tests/test_pyroma.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,32 @@
66

77
from PIL import __version__
88

9+
TYPE_CHECKING = False
10+
11+
if TYPE_CHECKING:
12+
from importlib.metadata import PackageMetadata
13+
914
pyroma = pytest.importorskip("pyroma", reason="Pyroma not installed")
1015

1116

12-
def map_metadata_keys(md):
17+
def map_metadata_keys(md: PackageMetadata) -> dict[str, str | list[str] | None]:
1318
# Convert installed wheel metadata into canonical Core Metadata 2.4 format.
1419
# This was a utility method in pyroma 4.3.3; it was removed in 5.0.
1520
# This implementation is constructed from the relevant logic from
1621
# Pyroma 5.0's `build_metadata()` implementation. This has been submitted
1722
# upstream to Pyroma as https://github.com/regebro/pyroma/pull/116,
1823
# so it may be possible to simplify this test in future.
1924
data = {}
20-
for key in set(md.keys()):
25+
for key in set(md):
2126
value = md.get_all(key)
2227
key = pyroma.projectdata.normalize(key)
2328

24-
if len(value) == 1:
25-
value = value[0]
26-
if value.strip() == "UNKNOWN":
27-
continue
28-
29-
data[key] = value
29+
if value is not None and len(value) == 1:
30+
first_value = value[0]
31+
if first_value.strip() != "UNKNOWN":
32+
data[key] = first_value
33+
else:
34+
data[key] = value
3035
return data
3136

3237

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ testpaths = [
217217
python_version = "3.10"
218218
pretty = true
219219
disallow_any_generics = true
220+
disallow_untyped_defs = true
220221
enable_error_code = "ignore-without-code"
221222
extra_checks = true
222223
follow_imports = "silent"

0 commit comments

Comments
 (0)