From 58da5d4d298b2339e9250b1bcd202791f74ac9c3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 14 Jan 2022 22:26:05 +0530 Subject: [PATCH] Placate mypy --- kittens/icat/main.py | 10 +++++----- kitty/rgb.py | 11 +---------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/kittens/icat/main.py b/kittens/icat/main.py index 1c87a4d3d..faa7cd40d 100755 --- a/kittens/icat/main.py +++ b/kittens/icat/main.py @@ -548,11 +548,11 @@ def main(args: List[str] = sys.argv) -> None: parsed_opts.z_index = parse_z_index(cli_opts.z_index) except Exception: raise SystemExit(f'Not a valid z-index specification: {cli_opts.z_index}') - try: - if cli_opts.background != 'none': - parsed_opts.remove_alpha = to_color(cli_opts.background, validate=True).as_sharp - except ValueError: - raise SystemExit(f'Not a valid color specification: {cli_opts.background}') + if cli_opts.background != 'none': + ra = to_color(cli_opts.background) + if ra is None: + raise SystemExit(f'Not a valid color specification: {cli_opts.background}') + parsed_opts.remove_alpha = ra.as_sharp parsed_opts.flip = cli_opts.mirror in ('both', 'vertical') parsed_opts.flop = cli_opts.mirror in ('both', 'horizontal') diff --git a/kitty/rgb.py b/kitty/rgb.py index b37d05657..ff0e9b3e6 100644 --- a/kitty/rgb.py +++ b/kitty/rgb.py @@ -3,12 +3,9 @@ import re from contextlib import suppress -from typing import Optional, overload, TYPE_CHECKING +from typing import Optional from .fast_data_types import Color -if TYPE_CHECKING: - from typing import Literal - def alpha_blend_channel(top_color: int, bottom_color: int, alpha: float) -> int: return int(alpha * top_color + (1 - alpha) * bottom_color) @@ -59,12 +56,6 @@ def color_as_sgr(x: Color) -> str: return x.as_sgr -@overload -def to_color(raw: str, validate: 'Literal[True]' = True) -> Color: ... -@overload -def to_color(raw: str, validate: 'Literal[False]' = False) -> Optional[Color]: ... - - def to_color(raw: str, validate: bool = False) -> Optional[Color]: # See man XParseColor x = raw.strip().lower()