Fix typing of to_color
This commit is contained in:
parent
8bb2da3c37
commit
dd31ee60f2
11
kitty/rgb.py
generated
11
kitty/rgb.py
generated
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user