Skip to content

Commit 877817b

Browse files
committed
Added type hint
1 parent 8494b06 commit 877817b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-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

0 commit comments

Comments
 (0)