From 0a6fb29e1005db7dbdef51f1debd558955e76b77 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Sat, 15 Jul 2023 21:46:00 -0400 Subject: [PATCH] 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. --- src/textual_paint/paint.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/textual_paint/paint.py b/src/textual_paint/paint.py index 30d45fe..5a05144 100755 --- a/src/textual_paint/paint.py +++ b/src/textual_paint/paint.py @@ -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."))