Fix typing of to_color

This commit is contained in:
Kovid Goyal 2022-01-14 21:54:36 +05:30
parent 8bb2da3c37
commit dd31ee60f2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

11
kitty/rgb.py generated
View File

@ -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()