Skip to content

Commit

Permalink
fix(python): with_content_type should resolve to specified file conte…
Browse files Browse the repository at this point in the history
…nt type when provided.
  • Loading branch information
eyw520 committed Nov 18, 2024
1 parent 0726aef commit e45d85f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions generators/python/core_utilities/shared/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit e45d85f

Please sign in to comment.