Skip to content

Add type annotations #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions colorsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

"""

try:
from typing import Tuple
except ImportError:
pass

__all__ = ["hls_to_rgb", "hsv_to_rgb"]

# Some floating point constants
Expand All @@ -36,7 +41,7 @@
# S: color saturation


def hls_to_rgb(hue, light, sat):
def hls_to_rgb(hue: float, light: float, sat: float) -> Tuple[float, float, float]:
""" Converts HLS to RGB values """
if sat == 0.0:
return light, light, light
Expand All @@ -52,7 +57,7 @@ def hls_to_rgb(hue, light, sat):
)


def _v(chroma1, chroma2, hue):
def _v(chroma1: float, chroma2: float, hue: float) -> float:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really specifically related to this PR but I'm curious if you know what this _v function is doing? I don't recognize the algorithm in it (tho I have little experience with light sensors and related things).

I wonder if there is a more descriptive name that we could use for it.

hue = hue % 1.0
if hue < ONE_SIXTH:
return chroma1 + (chroma2 - chroma1) * hue * 6.0
Expand All @@ -70,8 +75,8 @@ def _v(chroma1, chroma2, hue):


def hsv_to_rgb( # pylint: disable=too-many-return-statements,inconsistent-return-statements
hue, sat, val
):
hue: float, sat: float, val: float
) -> Tuple[float, float, float]:
""" Converts HSV to RGB values """
if sat == 0.0:
return val, val, val
Expand Down