Skip to content

Commit

Permalink
Replace "Mypy" with "Pyright".
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Dec 10, 2022
1 parent b7fb86c commit 8e5f37e
Show file tree
Hide file tree
Showing 325 changed files with 5,119 additions and 5,436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
pip install -r requirements.txt
- name: Static Type Checking
run: |
mypy --install-types --non-interactive --show-error-codes --warn-unused-ignores --warn-redundant-casts $CI_PACKAGE
pyright --skipunannotated
16 changes: 8 additions & 8 deletions colour/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,12 @@ def __getattr__(self, attribute) -> Any:
return super().__getattr__(attribute)


colour.__application_name__ = __application_name__ # type: ignore[attr-defined]
colour.__application_name__ = __application_name__ # pyright: ignore

colour.__major_version__ = __major_version__ # type: ignore[attr-defined]
colour.__minor_version__ = __minor_version__ # type: ignore[attr-defined]
colour.__change_version__ = __change_version__ # type: ignore[attr-defined]
colour.__version__ = __version__ # type: ignore[attr-defined]
colour.__major_version__ = __major_version__ # pyright: ignore
colour.__minor_version__ = __minor_version__ # pyright: ignore
colour.__change_version__ = __change_version__ # pyright: ignore
colour.__version__ = __version__ # pyright: ignore

# v0.4.0
API_CHANGES = {
Expand Down Expand Up @@ -943,14 +943,14 @@ def __getattr__(self, attribute) -> Any:
"""Defines the *colour.models* sub-package API changes."""

if not is_documentation_building():
sys.modules["colour"] = colour( # type: ignore[assignment]
sys.modules["colour"] = colour( # pyright: ignore
sys.modules["colour"], build_API_changes(API_CHANGES)
)

del ModuleAPI, is_documentation_building, build_API_changes, sys

colour.__disable_lazy_load__ = True # type: ignore[attr-defined]
__disable_lazy_load__ = colour.__disable_lazy_load__ # type: ignore[attr-defined]
colour.__disable_lazy_load__ = True # pyright: ignore
__disable_lazy_load__ = colour.__disable_lazy_load__ # pyright: ignore
"""
Ensures that the lazy loaded datasets are not transformed during import.
See :class:`colour.utilities.LazyCanonicalMapping` for more information.
Expand Down
4 changes: 2 additions & 2 deletions colour/adaptation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from __future__ import annotations

from colour.hints import Any, ArrayLike, Literal, NDArray, Union
from colour.hints import Any, ArrayLike, Literal, NDArrayFloat, Union
from colour.utilities import (
CanonicalMapping,
filter_kwargs,
Expand Down Expand Up @@ -136,7 +136,7 @@ def chromatic_adaptation(
str,
] = "Von Kries",
**kwargs: Any,
) -> NDArray:
) -> NDArrayFloat:
"""
Adapt given stimulus from test viewing conditions to reference viewing
conditions.
Expand Down
70 changes: 35 additions & 35 deletions colour/adaptation/cie1994.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
from colour.adaptation import CAT_VON_KRIES
from colour.hints import (
ArrayLike,
FloatingOrArrayLike,
FloatingOrNDArray,
NDArray,
NDArrayFloat,
)
from colour.utilities import (
as_float_array,
Expand Down Expand Up @@ -57,13 +55,15 @@
"corresponding_colour",
]

MATRIX_XYZ_TO_RGB_CIE1994: NDArray = CAT_VON_KRIES
MATRIX_XYZ_TO_RGB_CIE1994: NDArrayFloat = CAT_VON_KRIES
"""
*CIE 1994* colour appearance model *CIE XYZ* tristimulus values to cone
responses matrix.
"""

MATRIX_RGB_TO_XYZ_CIE1994: NDArray = np.linalg.inv(MATRIX_XYZ_TO_RGB_CIE1994)
MATRIX_RGB_TO_XYZ_CIE1994: NDArrayFloat = np.linalg.inv(
MATRIX_XYZ_TO_RGB_CIE1994
)
"""
*CIE 1994* colour appearance model cone responses to *CIE XYZ* tristimulus
values matrix.
Expand All @@ -74,11 +74,11 @@ def chromatic_adaptation_CIE1994(
XYZ_1: ArrayLike,
xy_o1: ArrayLike,
xy_o2: ArrayLike,
Y_o: FloatingOrArrayLike,
E_o1: FloatingOrArrayLike,
E_o2: FloatingOrArrayLike,
n: FloatingOrArrayLike = 1,
) -> NDArray:
Y_o: ArrayLike,
E_o1: ArrayLike,
E_o2: ArrayLike,
n: ArrayLike = 1,
) -> NDArrayFloat:
"""
Adapt given stimulus *CIE XYZ_1* tristimulus values from test viewing
conditions to reference viewing conditions using *CIE 1994* chromatic
Expand Down Expand Up @@ -174,7 +174,7 @@ def chromatic_adaptation_CIE1994(
return from_range_100(XYZ_2)


def XYZ_to_RGB_CIE1994(XYZ: ArrayLike) -> NDArray:
def XYZ_to_RGB_CIE1994(XYZ: ArrayLike) -> NDArrayFloat:
"""
Convert from *CIE XYZ* tristimulus values to cone responses.
Expand All @@ -198,7 +198,7 @@ def XYZ_to_RGB_CIE1994(XYZ: ArrayLike) -> NDArray:
return vector_dot(MATRIX_XYZ_TO_RGB_CIE1994, XYZ)


def RGB_to_XYZ_CIE1994(RGB: ArrayLike) -> NDArray:
def RGB_to_XYZ_CIE1994(RGB: ArrayLike) -> NDArrayFloat:
"""
Convert from cone responses to *CIE XYZ* tristimulus values.
Expand All @@ -222,7 +222,7 @@ def RGB_to_XYZ_CIE1994(RGB: ArrayLike) -> NDArray:
return vector_dot(MATRIX_RGB_TO_XYZ_CIE1994, RGB)


def intermediate_values(xy_o: ArrayLike) -> NDArray:
def intermediate_values(xy_o: ArrayLike) -> NDArrayFloat:
"""
Return the intermediate values :math:`\\xi`, :math:`\\eta`,
:math:`\\zeta`.
Expand Down Expand Up @@ -257,8 +257,8 @@ def intermediate_values(xy_o: ArrayLike) -> NDArray:


def effective_adapting_responses(
xez: ArrayLike, Y_o: FloatingOrArrayLike, E_o: FloatingOrArrayLike
) -> NDArray:
xez: ArrayLike, Y_o: ArrayLike, E_o: ArrayLike
) -> NDArrayFloat:
"""
Derive the effective adapting responses in the fundamental primary system
of the test or reference field.
Expand Down Expand Up @@ -296,7 +296,7 @@ def effective_adapting_responses(
return RGB_o


def beta_1(x: FloatingOrArrayLike) -> FloatingOrNDArray:
def beta_1(x: ArrayLike) -> NDArrayFloat:
"""
Compute the exponent :math:`\\beta_1` for the middle and long-wavelength
sensitive cones.
Expand All @@ -308,7 +308,7 @@ def beta_1(x: FloatingOrArrayLike) -> FloatingOrNDArray:
Returns
-------
:class:`numpy.floating` or :class:`numpy.ndarray`
:class:`numpy.ndarray`
Exponent :math:`\\beta_1`.
Examples
Expand All @@ -322,7 +322,7 @@ def beta_1(x: FloatingOrArrayLike) -> FloatingOrNDArray:
return (6.469 + 6.362 * x_p) / (6.469 + x_p)


def beta_2(x: FloatingOrArrayLike) -> FloatingOrNDArray:
def beta_2(x: ArrayLike) -> NDArrayFloat:
"""
Compute the exponent :math:`\\beta_2` for the short-wavelength sensitive
cones.
Expand All @@ -334,7 +334,7 @@ def beta_2(x: FloatingOrArrayLike) -> FloatingOrNDArray:
Returns
-------
:class:`numpy.floating` or :class:`numpy.ndarray`
:class:`numpy.ndarray`
Exponent :math:`\\beta_2`.
Examples
Expand All @@ -348,7 +348,7 @@ def beta_2(x: FloatingOrArrayLike) -> FloatingOrNDArray:
return 0.7844 * (8.414 + 8.091 * x_p) / (8.414 + x_p)


def exponential_factors(RGB_o: ArrayLike) -> NDArray:
def exponential_factors(RGB_o: ArrayLike) -> NDArrayFloat:
"""
Return the chromatic adaptation exponential factors :math:`\\beta_1(R_o)`,
:math:`\\beta_1(G_o)` and :math:`\\beta_2(B_o)` of given cone responses.
Expand Down Expand Up @@ -387,9 +387,9 @@ def K_coefficient(
xez_2: ArrayLike,
bRGB_o1: ArrayLike,
bRGB_o2: ArrayLike,
Y_o: FloatingOrArrayLike,
n: FloatingOrArrayLike = 1,
) -> FloatingOrNDArray:
Y_o: ArrayLike,
n: ArrayLike = 1,
) -> NDArrayFloat:
"""
Compute the coefficient :math:`K` for correcting the difference between
the test and references illuminances.
Expand Down Expand Up @@ -417,7 +417,7 @@ def K_coefficient(
Returns
-------
:class:`numpy.floating` or :class:`numpy.ndarray`
:class:`numpy.ndarray`
Coefficient :math:`K`.
Examples
Expand Down Expand Up @@ -455,10 +455,10 @@ def corresponding_colour(
xez_2: ArrayLike,
bRGB_o1: ArrayLike,
bRGB_o2: ArrayLike,
Y_o: FloatingOrArrayLike,
K: FloatingOrArrayLike,
n: FloatingOrArrayLike = 1,
) -> NDArray:
Y_o: ArrayLike,
K: ArrayLike,
n: ArrayLike = 1,
) -> NDArrayFloat:
"""
Compute the corresponding colour cone responses of given test sample cone
responses :math:`RGB_1`.
Expand Down Expand Up @@ -518,13 +518,13 @@ def corresponding_colour(
n = as_float_array(n)

def RGB_c(
x_1: NDArray,
x_2: NDArray,
y_1: NDArray,
y_2: NDArray,
z: NDArray,
n: NDArray,
) -> NDArray:
x_1: NDArrayFloat,
x_2: NDArrayFloat,
y_1: NDArrayFloat,
y_2: NDArrayFloat,
z: NDArrayFloat,
n: NDArrayFloat,
) -> NDArrayFloat:
"""Compute the corresponding colour cone responses component."""

with sdiv_mode():
Expand Down
26 changes: 12 additions & 14 deletions colour/adaptation/cmccat2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
from colour.algebra import vector_dot
from colour.hints import (
ArrayLike,
Floating,
FloatingOrArrayLike,
Literal,
NDArray,
NDArrayFloat,
Union,
)
from colour.utilities import (
Expand All @@ -59,7 +57,7 @@
"chromatic_adaptation_CMCCAT2000",
]

CAT_INVERSE_CMCCAT2000: NDArray = np.linalg.inv(CAT_CMCCAT2000)
CAT_INVERSE_CMCCAT2000: NDArrayFloat = np.linalg.inv(CAT_CMCCAT2000)
"""
Inverse *CMCCAT2000* chromatic adaptation transform.
Expand All @@ -81,7 +79,7 @@ class InductionFactors_CMCCAT2000(NamedTuple):
:cite:`Li2002a`, :cite:`Westland2012k`
"""

F: Floating
F: float


VIEWING_CONDITIONS_CMCCAT2000: CanonicalMapping = CanonicalMapping(
Expand All @@ -104,12 +102,12 @@ def chromatic_adaptation_forward_CMCCAT2000(
XYZ: ArrayLike,
XYZ_w: ArrayLike,
XYZ_wr: ArrayLike,
L_A1: FloatingOrArrayLike,
L_A2: FloatingOrArrayLike,
L_A1: ArrayLike,
L_A2: ArrayLike,
surround: InductionFactors_CMCCAT2000 = VIEWING_CONDITIONS_CMCCAT2000[
"Average"
],
) -> NDArray:
) -> NDArrayFloat:
"""
Adapt given stimulus *CIE XYZ* tristimulus values from test viewing
conditions to reference viewing conditions using *CMCCAT2000* forward
Expand Down Expand Up @@ -199,12 +197,12 @@ def chromatic_adaptation_inverse_CMCCAT2000(
XYZ_c: ArrayLike,
XYZ_w: ArrayLike,
XYZ_wr: ArrayLike,
L_A1: FloatingOrArrayLike,
L_A2: FloatingOrArrayLike,
L_A1: ArrayLike,
L_A2: ArrayLike,
surround: InductionFactors_CMCCAT2000 = VIEWING_CONDITIONS_CMCCAT2000[
"Average"
],
) -> NDArray:
) -> NDArrayFloat:
"""
Adapt given stimulus corresponding colour *CIE XYZ* tristimulus values
from reference viewing conditions to test viewing conditions using
Expand Down Expand Up @@ -296,13 +294,13 @@ def chromatic_adaptation_CMCCAT2000(
XYZ: ArrayLike,
XYZ_w: ArrayLike,
XYZ_wr: ArrayLike,
L_A1: FloatingOrArrayLike,
L_A2: FloatingOrArrayLike,
L_A1: ArrayLike,
L_A2: ArrayLike,
surround: InductionFactors_CMCCAT2000 = VIEWING_CONDITIONS_CMCCAT2000[
"Average"
],
direction: Union[Literal["Forward", "Inverse"], str] = "Forward",
) -> NDArray:
) -> NDArrayFloat:
"""
Adapt given stimulus *CIE XYZ* tristimulus values using given viewing
conditions.
Expand Down
Loading

0 comments on commit 8e5f37e

Please sign in to comment.