Skip to content

Commit

Permalink
Improve type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Sep 16, 2023
1 parent 5e4aef2 commit a1863b6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tcolorpy/_truecolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import namedtuple
from colorsys import rgb_to_hsv
from enum import Enum
from typing import List, Optional, Sequence, Tuple, Type, Union, cast # noqa
from typing import Any, List, Optional, Sequence, Tuple, Type, Union, cast # noqa

from ._const import CSI, RESET, AnsiBGColor, AnsiFGColor, AnsiStyle

Expand Down Expand Up @@ -68,7 +68,10 @@ def __init__(self, color: Union["Color", str, RGBTuple]) -> None:
self.__name = color.name # type: ignore
self.red, self.green, self.blue = color.red, color.green, color.blue # type: ignore

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
if not isinstance(other, Color):
return False

if self.name and other.name:
return self.name == other.name
elif self.name or other.name:
Expand All @@ -79,7 +82,10 @@ def __eq__(self, other) -> bool:

return False

def __ne__(self, other) -> bool:
def __ne__(self, other: Any) -> bool:
if not isinstance(other, Color):
return True

return not self.__eq__(other)

def __repr__(self) -> str:
Expand Down Expand Up @@ -131,13 +137,13 @@ def hsv(self) -> HSV:
def calc_scaler(self) -> int:
return self.red + self.green + self.blue

def calc_complementary(self):
def calc_complementary(self) -> "Color":
rgb = (self.red, self.green, self.blue)
n = max(rgb) + min(rgb)
return Color((n - self.red, n - self.green, n - self.blue))


def _normalize_enum(value, enum_class: Type[Enum]):
def _normalize_enum(value: Any, enum_class: Type[Enum]) -> Any:
if isinstance(value, enum_class):
return value

Expand Down

0 comments on commit a1863b6

Please sign in to comment.