From dd31ee60f239f7ca46cc0dd709006b4183654318 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 14 Jan 2022 21:54:36 +0530 Subject: [PATCH] Fix typing of to_color --- kitty/rgb.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kitty/rgb.py b/kitty/rgb.py index ff0e9b3e6..b37d05657 100644 --- a/kitty/rgb.py +++ b/kitty/rgb.py @@ -3,9 +3,12 @@ import re from contextlib import suppress -from typing import Optional +from typing import Optional, overload, TYPE_CHECKING 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) @@ -56,6 +59,12 @@ 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()