mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 14:21:33 +03:00
Reorder None case for mypy
While Pyright can narrow down the type of format_id from `str | None` to `str` based on `format_id in Image.SAVE` (where `Image.SAVE` is `dict[str, Any]`), mypy does not.
This commit is contained in:
parent
641a46e368
commit
0a6fb29e10
@ -832,7 +832,9 @@ class AnsiArtDocument:
|
||||
def encode_to_format(self, format_id: str | None) -> bytes:
|
||||
"""Encode the image into the given file format."""
|
||||
# print("Supported image formats for writing:", Image.SAVE.keys())
|
||||
if format_id == "ANSI":
|
||||
if format_id is None:
|
||||
raise FormatWriteNotSupported(localized_message=_("Unknown file extension.") + "\n\n" + _("To save your changes, use a different filename."))
|
||||
elif format_id == "ANSI":
|
||||
# This maybe shouldn't use UTF-8... but there's not a singular encoding for "ANSI art".
|
||||
return self.get_ansi().encode("utf-8")
|
||||
elif format_id == "IRC":
|
||||
@ -848,8 +850,6 @@ class AnsiArtDocument:
|
||||
return self.get_rich_console_markup().encode("utf-8")
|
||||
elif format_id in Image.SAVE and format_id not in SAVE_DISABLED_FORMATS:
|
||||
return self.encode_image_format(format_id)
|
||||
elif format_id is None:
|
||||
raise FormatWriteNotSupported(localized_message=_("Unknown file extension.") + "\n\n" + _("To save your changes, use a different filename."))
|
||||
else:
|
||||
raise FormatWriteNotSupported(localized_message=_("Cannot write files in %1 format.", format_id) + "\n\n" + _("To save your changes, use a different filename."))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user