From e45d85f8d10958e504b2e2ff03dc5d2c329872b5 Mon Sep 17 00:00:00 2001 From: Eden Date: Mon, 18 Nov 2024 15:09:08 -0500 Subject: [PATCH] fix(python): with_content_type should resolve to specified file content type when provided. --- generators/python/core_utilities/shared/file.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/generators/python/core_utilities/shared/file.py b/generators/python/core_utilities/shared/file.py index c7341b7ffad..1f51f9f5074 100644 --- a/generators/python/core_utilities/shared/file.py +++ b/generators/python/core_utilities/shared/file.py @@ -48,13 +48,15 @@ def with_content_type(*, file: File, content_type: str) -> File: filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore return (filename, content, content_type) elif len(file) == 3: - filename, content, _ = cast(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore - return (filename, content, content_type) + filename, content, file_content_type = cast(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore + out_content_type = file_content_type or content_type + return (filename, content, out_content_type) elif len(file) == 4: - filename, content, _, headers = cast( # type: ignore + filename, content, file_content_type, headers = cast( # type: ignore Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], file ) - return (filename, content, content_type, headers) + out_content_type = file_content_type or content_type + return (filename, content, out_content_type, headers) else: raise ValueError(f"Unexpected tuple length: {len(file)}") return (None, file, content_type)