From ebd2ada4a32f8db32d909aa7284fcb921f3e482c Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Sun, 26 Apr 2020 06:01:45 -0400 Subject: [PATCH] Simplify metadata typing --- twine/commands/check.py | 6 +++--- twine/package.py | 3 +-- twine/repository.py | 4 +--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/twine/commands/check.py b/twine/commands/check.py index d8e3f579..1ecac73b 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -80,8 +80,8 @@ def _check_file( package = package_file.PackageFile.from_filename(filename, comment=None) metadata = package.metadata_dictionary() - description = metadata["description"] - description_content_type = metadata["description_content_type"] + description = cast(str, metadata["description"]) + description_content_type = cast(str, metadata["description_content_type"]) if description_content_type is None: warnings.append( @@ -89,7 +89,7 @@ def _check_file( ) description_content_type = "text/x-rst" - content_type, params = cgi.parse_header(cast(str, description_content_type)) + content_type, params = cgi.parse_header(description_content_type) renderer = _RENDERERS.get(content_type, _RENDERERS[None]) if description in {None, "UNKNOWN\n\n\n"}: diff --git a/twine/package.py b/twine/package.py index abfb0c64..892141fa 100644 --- a/twine/package.py +++ b/twine/package.py @@ -16,7 +16,6 @@ import io import os import subprocess -from typing import IO from typing import Dict from typing import Optional from typing import Sequence @@ -46,7 +45,7 @@ ".zip": "sdist", } -MetadataValue = Union[str, Sequence[str], Tuple[str, IO, str]] +MetadataValue = Union[str, Sequence[str]] class PackageFile: diff --git a/twine/repository.py b/twine/repository.py index 8a82baa4..08eb0cb0 100644 --- a/twine/repository.py +++ b/twine/repository.py @@ -103,9 +103,7 @@ def close(self) -> None: self.session.close() @staticmethod - def _convert_data_to_list_of_tuples( - data: Dict[str, package_file.MetadataValue] - ) -> List[Tuple[str, package_file.MetadataValue]]: + def _convert_data_to_list_of_tuples(data: Dict[str, Any]) -> List[Tuple[str, Any]]: data_to_send = [] for key, value in data.items(): if key in KEYWORDS_TO_NOT_FLATTEN or not isinstance(value, (list, tuple)):