Skip to content
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

PR: Enable all relevant *Ruff* checks. #1318

Merged
merged 42 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
268b4ce
Update `requirements.txt` file.
KelSolaar Dec 21, 2024
8bbeaa8
Fix incorrect if clause in `colour.utilities.verbose.show_warning` de…
KelSolaar Dec 21, 2024
0945416
Remove unused warning in `colour.characterisation.aces_it` module.
KelSolaar Dec 21, 2024
16befc1
Update `README.rst` file.
KelSolaar Dec 21, 2024
994043d
Enable all *Ruff* fixes.
KelSolaar Dec 22, 2024
3f130e2
Enable `ANN` checks.
KelSolaar Dec 21, 2024
a6f95eb
Enable `B008` check.
KelSolaar Dec 21, 2024
44e6142
Enable `B905` check.
KelSolaar Dec 21, 2024
227af2c
Enable `D104` check.
KelSolaar Dec 21, 2024
9bbfe9e
Enable `PIE804` check.
KelSolaar Dec 21, 2024
7b6453e
Enable `PLE0605` check.
KelSolaar Dec 21, 2024
a90c3ae
Enable `PLR0911` check.
KelSolaar Dec 21, 2024
14c3271
Enable `RET504` check.
KelSolaar Dec 21, 2024
2e59bf9
Enable `RET505` check.
KelSolaar Dec 21, 2024
6a9ac95
Enable `RET506` check.
KelSolaar Dec 21, 2024
daa5195
Enable `RET507` check.
KelSolaar Dec 21, 2024
6eb5a2c
Enable `RET508` check.
KelSolaar Dec 21, 2024
25e2aa4
Enable `TRY300` check.
KelSolaar Dec 21, 2024
68510d7
Update `pyproject.toml` file.
KelSolaar Dec 21, 2024
5473200
Enable `BLE001` check.
KelSolaar Dec 21, 2024
5c78b8f
Enable `EM` checks.
KelSolaar Dec 21, 2024
b7af688
Enable `PD` checks.
KelSolaar Dec 21, 2024
1e5c7db
Enable `ASYNC` checks.
KelSolaar Dec 21, 2024
6ce113e
Enable `CPY` checks.
KelSolaar Dec 21, 2024
dc65e7a
Enable `FA` checks.
KelSolaar Dec 21, 2024
044aa30
Enable `LOG` checks.
KelSolaar Dec 21, 2024
d32dfc1
Enable `PYI` checks.
KelSolaar Dec 22, 2024
027d333
Enable `RSE` checks.
KelSolaar Dec 22, 2024
82c1bf1
Enable `SLF` checks.
KelSolaar Dec 22, 2024
c023a2c
Enable `SLOT` checks.
KelSolaar Dec 22, 2024
6966df6
Enable `TC` checks.
KelSolaar Dec 22, 2024
8d621f1
Enable `INT` checks.
KelSolaar Dec 22, 2024
623b437
Update `pyproject.toml` file.
KelSolaar Dec 22, 2024
08feb3b
Enable `R` checks.
KelSolaar Dec 22, 2024
fe08ef5
Enable `FLY` checks.
KelSolaar Dec 22, 2024
869a522
Enable `NPY` checks.
KelSolaar Dec 22, 2024
7eee264
Enable `PERF` checks.
KelSolaar Dec 22, 2024
23ee406
Enable `FURB` checks.
KelSolaar Dec 22, 2024
2ad6031
Enable `DOC` checks.
KelSolaar Dec 22, 2024
58f96f7
Enable all the *Ruff* checks but the currently ignored ones.
KelSolaar Dec 22, 2024
9cff811
Use typing overload to improve typing annotations.
KelSolaar Dec 22, 2024
baf108e
Code formatting.
KelSolaar Dec 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ sigterm = True
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
if TYPE_CHECKING:
pass
22 changes: 11 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1827,17 +1827,17 @@ Reflectance Recovery

.. code-block:: text

SpectralDistribution([[ 3.60000000e+02, 8.52694330e-02],
[ 3.65000000e+02, 8.52203359e-02],
[ 3.70000000e+02, 8.52841304e-02],
...
[ 7.70000000e+02, 4.46546872e-01],
[ 7.75000000e+02, 4.46638451e-01],
[ 7.80000000e+02, 4.46641739e-01]],
SpragueInterpolator,
{},
Extrapolator,
{'method': 'Constant', 'left': None, 'right': None})
SpectralDistribution([[ 3.60000000e+02, 8.52694330e-02],
[ 3.65000000e+02, 8.52203359e-02],
[ 3.70000000e+02, 8.52841304e-02],
...
[ 7.70000000e+02, 4.46546872e-01],
[ 7.75000000e+02, 4.46638451e-01],
[ 7.80000000e+02, 4.46641739e-01]],
SpragueInterpolator,
{},
Extrapolator,
{'method': 'Constant', 'left': None, 'right': None})

.. code-block:: python

Expand Down
4 changes: 2 additions & 2 deletions colour/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@
__major_version__ = "0"
__minor_version__ = "4"
__change_version__ = "6"
__version__ = ".".join((__major_version__, __minor_version__, __change_version__))
__version__ = f"{__major_version__}.{__minor_version__}.{__change_version__}"

# TODO: Remove legacy printing support when deemed appropriate.
with contextlib.suppress(TypeError):
Expand All @@ -923,7 +923,7 @@
class colour(ModuleAPI):
"""Define a class acting like the *colour* module."""

def __getattr__(self, attribute) -> Any:
def __getattr__(self, attribute: str) -> Any:
"""Return the value from the attribute with given name."""

return super().__getattr__(attribute)
Expand Down
6 changes: 5 additions & 1 deletion colour/adaptation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@

from __future__ import annotations

from colour.hints import Any, ArrayLike, Literal, NDArrayFloat
import typing

if typing.TYPE_CHECKING:
from colour.hints import Any, ArrayLike, Literal, NDArrayFloat

from colour.utilities import (
CanonicalMapping,
filter_kwargs,
Expand Down
23 changes: 10 additions & 13 deletions colour/adaptation/cie1994.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@

from __future__ import annotations

import typing

import numpy as np

from colour.adaptation import CAT_VON_KRIES
from colour.algebra import sdiv, sdiv_mode, spow, vecmul
from colour.hints import ArrayLike, NDArrayFloat

if typing.TYPE_CHECKING:
from colour.hints import ArrayLike, NDArrayFloat

from colour.utilities import (
as_float_array,
from_range_100,
Expand Down Expand Up @@ -244,9 +249,7 @@ def intermediate_values(xy_o: ArrayLike) -> NDArrayFloat:
eta = (-0.27200 * x_o + 1.11962 * y_o + 0.04570) / y_o
zeta = (0.91822 * (1 - x_o - y_o)) / y_o

xez = tstack([xi, eta, zeta])

return xez
return tstack([xi, eta, zeta])


def effective_adapting_responses(
Expand Down Expand Up @@ -284,9 +287,7 @@ def effective_adapting_responses(
Y_o = as_float_array(Y_o)
E_o = as_float_array(E_o)

RGB_o = ((Y_o[..., None] * E_o[..., None]) / (100 * np.pi)) * xez

return RGB_o
return ((Y_o[..., None] * E_o[..., None]) / (100 * np.pi)) * xez


def beta_1(x: ArrayLike) -> NDArrayFloat:
Expand Down Expand Up @@ -370,9 +371,7 @@ def exponential_factors(RGB_o: ArrayLike) -> NDArrayFloat:
bG_o = beta_1(G_o)
bB_o = beta_2(B_o)

bRGB_o = tstack([bR_o, bG_o, bB_o])

return bRGB_o
return tstack([bR_o, bG_o, bB_o])


def K_coefficient(
Expand Down Expand Up @@ -529,6 +528,4 @@ def RGB_c(
G_2 = RGB_c(eta_1, eta_2, bG_o1, bG_o2, G_1, n)
B_2 = RGB_c(zeta_1, zeta_2, bB_o1, bB_o2, B_1, n)

RGB_2 = tstack([R_2, G_2, B_2])

return RGB_2
return tstack([R_2, G_2, B_2])
20 changes: 13 additions & 7 deletions colour/adaptation/cmccat2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@

from __future__ import annotations

from typing import NamedTuple
import typing
from dataclasses import dataclass

import numpy as np

from colour.adaptation import CAT_CMCCAT2000
from colour.algebra import vecmul
from colour.hints import ArrayLike, Literal, NDArrayFloat

if typing.TYPE_CHECKING:
from colour.hints import ArrayLike, Literal, NDArrayFloat

from colour.utilities import (
CanonicalMapping,
MixinDataclassIterable,
as_float_array,
from_range_100,
to_domain_100,
Expand Down Expand Up @@ -61,7 +66,8 @@
"""


class InductionFactors_CMCCAT2000(NamedTuple):
@dataclass(frozen=True)
class InductionFactors_CMCCAT2000(MixinDataclassIterable):
"""
*CMCCAT2000* chromatic adaptation model induction factors.

Expand Down Expand Up @@ -380,7 +386,7 @@ def chromatic_adaptation_CMCCAT2000(
return chromatic_adaptation_forward_CMCCAT2000(
XYZ, XYZ_w, XYZ_wr, L_A1, L_A2, surround
)
else:
return chromatic_adaptation_inverse_CMCCAT2000(
XYZ, XYZ_w, XYZ_wr, L_A1, L_A2, surround
)

return chromatic_adaptation_inverse_CMCCAT2000(
XYZ, XYZ_w, XYZ_wr, L_A1, L_A2, surround
)
6 changes: 5 additions & 1 deletion colour/adaptation/datasets/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@

from __future__ import annotations

import typing

import numpy as np

from colour.hints import NDArrayFloat
if typing.TYPE_CHECKING:
from colour.hints import NDArrayFloat

from colour.utilities import CanonicalMapping

__author__ = "Colour Developers"
Expand Down
12 changes: 8 additions & 4 deletions colour/adaptation/fairchild1990.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@

from __future__ import annotations

import typing

import numpy as np

from colour.adaptation import CAT_VON_KRIES
from colour.algebra import sdiv, sdiv_mode, spow, vecmul
from colour.hints import ArrayLike, NDArrayFloat

if typing.TYPE_CHECKING:
from colour.hints import ArrayLike, NDArrayFloat

from colour.utilities import (
as_float_array,
from_range_100,
Expand Down Expand Up @@ -240,6 +245,7 @@ def degrees_of_adaptation(
"""

LMS = as_float_array(LMS)

if discount_illuminant:
return ones(LMS.shape)

Expand All @@ -265,6 +271,4 @@ def P_c(x: NDArrayFloat) -> NDArrayFloat:
)

with sdiv_mode():
p_LMS = P_c(m_E(LMS, LMS_E))

return p_LMS
return P_c(m_E(LMS, LMS_E))
23 changes: 15 additions & 8 deletions colour/adaptation/fairchild2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@

from __future__ import annotations

from collections import namedtuple
import typing
from dataclasses import dataclass

import numpy as np

from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS
from colour.algebra import sdiv, sdiv_mode, vecmul
from colour.hints import ArrayLike, Literal, NDArrayFloat

if typing.TYPE_CHECKING:
from colour.hints import ArrayLike, Literal, NDArrayFloat

from colour.utilities import (
CanonicalMapping,
MixinDataclassIterable,
as_float_array,
from_range_1,
row_as_diagonal,
Expand All @@ -49,9 +54,8 @@
]


class Coefficients_DegreeOfAdaptation_vK20(
namedtuple("Coefficients_DegreeOfAdaptation_vK20", ("D_n", "D_r", "D_p"))
):
@dataclass(frozen=True)
class Coefficients_DegreeOfAdaptation_vK20(MixinDataclassIterable):
"""
*Von Kries 2020* (*vK20*) degree of adaptation coefficients.

Expand All @@ -69,6 +73,10 @@ class Coefficients_DegreeOfAdaptation_vK20(
:cite:`Fairchild2020`
"""

D_n: float
D_r: float
D_p: float


CONDITIONS_DEGREE_OF_ADAPTATION_VK20: CanonicalMapping = CanonicalMapping(
{
Expand Down Expand Up @@ -200,7 +208,7 @@ def matrix_chromatic_adaptation_vk20(

M = CHROMATIC_ADAPTATION_TRANSFORMS[transform]

D_n, D_r, D_p = coefficients
D_n, D_r, D_p = coefficients.values

LMS_n = vecmul(M, XYZ_n)
LMS_r = vecmul(M, XYZ_r)
Expand All @@ -210,9 +218,8 @@ def matrix_chromatic_adaptation_vk20(
D = row_as_diagonal(sdiv(1, (D_n * LMS_n + D_r * LMS_r + D_p * LMS_p)))

M_CAT = np.matmul(np.linalg.inv(M), D)
M_CAT = np.matmul(M_CAT, M)

return M_CAT
return np.matmul(M_CAT, M)


def chromatic_adaptation_vK20(
Expand Down
8 changes: 5 additions & 3 deletions colour/adaptation/tests/test__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Define the unit tests for the :mod:`colour.adaptation` module."""

from __future__ import annotations

import numpy as np

from colour.adaptation import chromatic_adaptation
Expand All @@ -24,7 +26,7 @@ class TestChromaticAdaptation:
tests methods.
"""

def test_chromatic_adaptation(self):
def test_chromatic_adaptation(self) -> None:
"""Test :func:`colour.adaptation.chromatic_adaptation` definition."""

XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
Expand Down Expand Up @@ -68,7 +70,7 @@ def test_chromatic_adaptation(self):
atol=TOLERANCE_ABSOLUTE_TESTS,
)

def test_domain_range_scale_chromatic_adaptation(self):
def test_domain_range_scale_chromatic_adaptation(self) -> None:
"""
Test :func:`colour.adaptation.chromatic_adaptation` definition domain
and range scale support.
Expand Down Expand Up @@ -100,7 +102,7 @@ def test_domain_range_scale_chromatic_adaptation(self):
]

d_r = (("reference", 1), ("1", 1), ("100", 100))
for method, value in zip(m, v):
for method, value in zip(m, v, strict=True):
for scale, factor in d_r:
with domain_range_scale(scale):
np.testing.assert_allclose(
Expand Down
10 changes: 6 additions & 4 deletions colour/adaptation/tests/test_cie1994.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Define the unit tests for the :mod:`colour.adaptation.cie1994` module."""

from __future__ import annotations

from itertools import product

import numpy as np
Expand All @@ -26,7 +28,7 @@ class TestChromaticAdaptationCIE1994:
definition unit tests methods.
"""

def test_chromatic_adaptation_CIE1994(self):
def test_chromatic_adaptation_CIE1994(self) -> None:
"""
Test :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`
definition.
Expand Down Expand Up @@ -71,7 +73,7 @@ def test_chromatic_adaptation_CIE1994(self):
atol=TOLERANCE_ABSOLUTE_TESTS,
)

def test_n_dimensional_chromatic_adaptation_CIE1994(self):
def test_n_dimensional_chromatic_adaptation_CIE1994(self) -> None:
"""
Test :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`
definition n-dimensional arrays support.
Expand Down Expand Up @@ -117,7 +119,7 @@ def test_n_dimensional_chromatic_adaptation_CIE1994(self):
atol=TOLERANCE_ABSOLUTE_TESTS,
)

def test_domain_range_scale_chromatic_adaptation_CIE1994(self):
def test_domain_range_scale_chromatic_adaptation_CIE1994(self) -> None:
"""
Test :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`
definition domain and range scale support.
Expand All @@ -143,7 +145,7 @@ def test_domain_range_scale_chromatic_adaptation_CIE1994(self):
)

@ignore_numpy_errors
def test_nan_chromatic_adaptation_CIE1994(self):
def test_nan_chromatic_adaptation_CIE1994(self) -> None:
"""
Test :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`
definition nan support.
Expand Down
Loading
Loading