diff --git a/tests/test_package.py b/tests/test_package.py index 0b883da3..63690ad4 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -340,20 +340,35 @@ def test_fips_metadata_excludes_md5_and_blake2(monkeypatch): "read_data, missing_fields", [ pytest.param( - b"Metadata-Version: 2.3\nName: test-package\nVersion: 1.0.0\n", + b"Metadata-Version: 102.3\nName: test-package\nVersion: 1.0.0\n", "Name, Version", id="unsupported Metadata-Version", ), + pytest.param( + b"Metadata-Version: 2.3\nName: UNKNOWN\nVersion: UNKNOWN\n", + "Name, Version", + id="missing Name and Version", + ), pytest.param( b"Metadata-Version: 2.2\nName: UNKNOWN\nVersion: UNKNOWN\n", "Name, Version", id="missing Name and Version", ), + pytest.param( + b"Metadata-Version: 2.3\nName: UNKNOWN\nVersion: 1.0.0\n", + "Name", + id="missing Name", + ), pytest.param( b"Metadata-Version: 2.2\nName: UNKNOWN\nVersion: 1.0.0\n", "Name", id="missing Name", ), + pytest.param( + b"Metadata-Version: 2.3\nName: test-package\nVersion: UNKNOWN\n", + "Version", + id="missing Version", + ), pytest.param( b"Metadata-Version: 2.2\nName: test-package\nVersion: UNKNOWN\n", "Version", diff --git a/twine/cli.py b/twine/cli.py index 46d6d01b..debe6199 100644 --- a/twine/cli.py +++ b/twine/cli.py @@ -118,6 +118,6 @@ def dispatch(argv: List[str]) -> Any: configure_output() - main = registered_commands[args.command].load() # type: ignore[no-untyped-call] # python/importlib_metadata#288 # noqa: E501 + main = registered_commands[args.command].load() return main(args.args) diff --git a/twine/wheel.py b/twine/wheel.py index cf90eab7..7af1d804 100644 --- a/twine/wheel.py +++ b/twine/wheel.py @@ -16,6 +16,7 @@ import re import zipfile from typing import List, Optional +from typing import cast as type_cast from pkginfo import distribution @@ -87,5 +88,7 @@ def parse(self, data: bytes) -> None: super().parse(data) fp = io.StringIO(data.decode("utf-8", errors="replace")) + # msg is ``email.message.Message`` which is a legacy API documented + # here: https://docs.python.org/3/library/email.compat32-message.html msg = distribution.parse(fp) - self.description = msg.get_payload() + self.description = type_cast(str, msg.get_payload())