-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add type stub for colour package #15823
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
base: main
Are you sure you want to change the base?
Changes from all commits
e87a4a7
3c03e51
be75a9a
78b09e2
3654862
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| colour.Color.set_hex_l |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| version = "0.1.5" | ||
| upstream-repository = "https://github.com/vaab/colour" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,102 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||||||||||||||||
| from collections.abc import Callable, Generator, Hashable | ||||||||||||||||||||||||||||||||||||||||||
| from types import NotImplementedType | ||||||||||||||||||||||||||||||||||||||||||
| from typing import Any, Final, final, overload | ||||||||||||||||||||||||||||||||||||||||||
| from typing_extensions import Self | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| FLOAT_ERROR: Final[float] = 0.0000005 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| RGB_TO_COLOR_NAMES: Final[dict[tuple[int, int, int], list[str]]] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| COLOR_NAME_TO_RGB: Final[dict[list[str], tuple[int, int, int]]] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| LONG_HEX_COLOR: Final[re.Pattern[str]] | ||||||||||||||||||||||||||||||||||||||||||
| SHORT_HEX_COLOR: Final[re.Pattern[str]] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @final | ||||||||||||||||||||||||||||||||||||||||||
| class C_HSL: | ||||||||||||||||||||||||||||||||||||||||||
| def __getattr__(self, value: str) -> tuple[float, float, float]: ... | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @final | ||||||||||||||||||||||||||||||||||||||||||
| class C_RGB: | ||||||||||||||||||||||||||||||||||||||||||
| def __getattr__(self, value: str) -> tuple[float, float, float]: ... | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @final | ||||||||||||||||||||||||||||||||||||||||||
| class C_HEX: | ||||||||||||||||||||||||||||||||||||||||||
| def __getattr__(self, value: str) -> str: ... | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| HSL: Final[C_HSL] | ||||||||||||||||||||||||||||||||||||||||||
| RGB: Final[C_RGB] | ||||||||||||||||||||||||||||||||||||||||||
| HEX: Final[C_HEX] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def hsl2rgb(hsl: tuple[float, float, float]) -> tuple[float, float, float]: ... | ||||||||||||||||||||||||||||||||||||||||||
| def rgb2hsl(rgb: tuple[float, float, float]) -> tuple[float, float, float]: ... | ||||||||||||||||||||||||||||||||||||||||||
| def _hue2rgb(v1: float, v2: float, vH: float) -> float: ... | ||||||||||||||||||||||||||||||||||||||||||
| def rgb2hex(rgb: tuple[float, float, float], force_long: bool = False) -> str: ... | ||||||||||||||||||||||||||||||||||||||||||
| def hex2rgb(str_rgb: str) -> tuple[float, float, float]: ... | ||||||||||||||||||||||||||||||||||||||||||
| def hex2web(hex: str) -> str: ... | ||||||||||||||||||||||||||||||||||||||||||
| def web2hex(web: str, force_long: bool = False) -> str: ... | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| hsl2hex: Final[Callable[[tuple[float, float, float]], str]] | ||||||||||||||||||||||||||||||||||||||||||
| hex2hsl: Final[Callable[[str], tuple[float, float, float]]] | ||||||||||||||||||||||||||||||||||||||||||
| rgb2web: Final[Callable[[tuple[float, float, float]], str]] | ||||||||||||||||||||||||||||||||||||||||||
| web2rgb: Final[Callable[[str], tuple[float, float, float]]] | ||||||||||||||||||||||||||||||||||||||||||
| web2hsl: Final[Callable[[str], tuple[float, float, float]]] | ||||||||||||||||||||||||||||||||||||||||||
| hsl2web: Final[Callable[[tuple[float, float, float]], str]] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def color_scale( | ||||||||||||||||||||||||||||||||||||||||||
| begin_hsl: tuple[float, float, float], end_hsl: tuple[float, float, float], nb: int | ||||||||||||||||||||||||||||||||||||||||||
| ) -> tuple[float, float, float]: ... | ||||||||||||||||||||||||||||||||||||||||||
| def RGB_color_picker(obj: Any) -> Color: ... | ||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this will work with literally every object:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @overload | ||||||||||||||||||||||||||||||||||||||||||
| def hash_or_str(obj: Hashable) -> int: ... | ||||||||||||||||||||||||||||||||||||||||||
| @overload | ||||||||||||||||||||||||||||||||||||||||||
| def hash_or_str(obj: object) -> str: ... # type: ignore[overload-cannot-match] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| class Color: | ||||||||||||||||||||||||||||||||||||||||||
| def __init__( | ||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||
| color: Self | str | None = None, | ||||||||||||||||||||||||||||||||||||||||||
| pick_for: object | None = None, | ||||||||||||||||||||||||||||||||||||||||||
| picker: Callable[[object], Color] = ..., | ||||||||||||||||||||||||||||||||||||||||||
| pick_key: Callable[[object], int | str] = ..., | ||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Any, | ||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we need documentation for non-obvious uses of
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| ) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def __getattr__(self, label: str) -> Any: ... | ||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably better expressed by just copying the |
||||||||||||||||||||||||||||||||||||||||||
| def __setattr__(self, label: str, value: Any) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here (but as attribute setters, except for |
||||||||||||||||||||||||||||||||||||||||||
| def get_hsl(self) -> tuple[float, float, float]: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_hex(self) -> str: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_hex_l(self) -> str: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_rgb(self) -> tuple[float, float, float]: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_hue(self) -> float: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_saturation(self) -> float: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_luminance(self) -> float: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_red(self) -> float: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_green(self) -> float: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_blue(self) -> float: ... | ||||||||||||||||||||||||||||||||||||||||||
| def get_web(self) -> str: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_hsl(self, value: float) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_rgb(self, value: float) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_hue(self, value: float) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_saturation(self, value: float) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_luminance(self, value: float) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_red(self, value: float) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_green(self, value: float) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_blue(self, value: float) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def set_hex(self, value: str) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| set_hex_l: Final[Callable[[str], None]] = ... | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def set_web(self, value: str) -> None: ... | ||||||||||||||||||||||||||||||||||||||||||
| def range_to(self, value: str | Color | None, steps: int) -> Generator[Color]: ... | ||||||||||||||||||||||||||||||||||||||||||
| def __eq__(self, other: object) -> bool | NotImplementedType: ... # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| RGB_equivalence: Final[Callable[[Color, Color], bool]] | ||||||||||||||||||||||||||||||||||||||||||
| HSL_equivalence: Final[Callable[[Color, Color], bool]] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def make_color_factory( | ||||||||||||||||||||||||||||||||||||||||||
| **kwargs_defaults: Any, | ||||||||||||||||||||||||||||||||||||||||||
| ) -> Callable[ | ||||||||||||||||||||||||||||||||||||||||||
| [Color | str | None, object | None, Callable[[object], Color], object | None, Callable[[object], int | str]], Color | ||||||||||||||||||||||||||||||||||||||||||
| ]: ... | ||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be expressed using a callable protocol:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.