Skip to content

[pre-commit.ci] pre-commit autoupdate #1080

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
args:
@@ -25,11 +25,11 @@ repos:
]
exclude: "BIBLIOGRAPHY.bib|CONTRIBUTORS.rst"
- repo: https://github.com/PyCQA/isort
rev: "5.13.2"
rev: "6.0.1"
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.2"
rev: "v0.11.8"
hooks:
- id: ruff-format
- id: ruff
33 changes: 11 additions & 22 deletions colour/algebra/common.py
Original file line number Diff line number Diff line change
@@ -73,18 +73,16 @@
"""


def get_sdiv_mode() -> (
Literal[
"Numpy",
"Ignore",
"Warning",
"Raise",
"Ignore Zero Conversion",
"Warning Zero Conversion",
"Ignore Limit Conversion",
"Warning Limit Conversion",
]
):
def get_sdiv_mode() -> Literal[
"Numpy",
"Ignore",
"Warning",
"Raise",
"Ignore Zero Conversion",
"Warning Zero Conversion",
"Ignore Limit Conversion",
"Warning Limit Conversion",
]:
"""
Return *Colour* safe division mode.

@@ -144,16 +142,7 @@ def set_sdiv_mode(
global _SDIV_MODE # noqa: PLW0603

_SDIV_MODE = cast(
Literal[
"Numpy",
"Ignore",
"Warning",
"Raise",
"Ignore Zero Conversion",
"Warning Zero Conversion",
"Ignore Limit Conversion",
"Warning Limit Conversion",
],
"Literal['Numpy', 'Ignore', 'Warning', 'Raise', 'Ignore Zero Conversion', 'Warning Zero Conversion', 'Ignore Limit Conversion', 'Warning Limit Conversion']",
validate_method(
mode,
(
14 changes: 6 additions & 8 deletions colour/algebra/interpolation.py
Original file line number Diff line number Diff line change
@@ -758,8 +758,7 @@ class NearestNeighbourInterpolator(KernelInterpolator):

def __init__(self, *args: Any, **kwargs: Any) -> None:
kwargs["kernel"] = kernel_nearest_neighbour
if "kernel_kwargs" in kwargs:
del kwargs["kernel_kwargs"]
kwargs.pop("kernel_kwargs", None)

super().__init__(*args, **kwargs)

@@ -850,7 +849,7 @@ def x(self) -> NDArrayFloat:
def x(self, value: ArrayLike) -> None:
"""Setter for the **self.x** property."""

value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype))
value = cast("NDArrayFloat", np.atleast_1d(value).astype(self._dtype))

attest(
value.ndim == 1,
@@ -883,7 +882,7 @@ def y(self) -> NDArrayFloat:
def y(self, value: ArrayLike) -> None:
"""Setter for the **self.y** property."""

value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype))
value = cast("NDArrayFloat", np.atleast_1d(value).astype(self._dtype))

attest(
value.ndim == 1,
@@ -1136,8 +1135,7 @@ def y(self, value: ArrayLike) -> None:

attest(
len(value) >= 6,
'"y" dependent variable values count must be equal to or '
"greater than 6!",
'"y" dependent variable values count must be equal to or greater than 6!',
)

self._y = value
@@ -1423,7 +1421,7 @@ def x(self) -> NDArrayFloat:
def x(self, value: ArrayLike) -> None:
"""Setter for the **self.x** property."""

value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype))
value = cast("NDArrayFloat", np.atleast_1d(value).astype(self._dtype))

attest(
value.ndim == 1,
@@ -1456,7 +1454,7 @@ def y(self) -> NDArrayFloat:
def y(self, value: ArrayLike) -> None:
"""Setter for the **self.y** property."""

value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype))
value = cast("NDArrayFloat", np.atleast_1d(value).astype(self._dtype))

attest(
value.ndim == 1,
2 changes: 1 addition & 1 deletion colour/algebra/tests/test_interpolation.py
Original file line number Diff line number Diff line change
@@ -483,7 +483,7 @@
)

LUT_TABLE: NDArrayFloat = cast(
LUT3D,
"LUT3D",
read_LUT(
os.path.join(
os.path.dirname(__file__),
4 changes: 2 additions & 2 deletions colour/appearance/ciecam02.py
Original file line number Diff line number Diff line change
@@ -777,7 +777,7 @@ def full_chromatic_adaptation_forward(
with sdiv_mode():
RGB_c = (Y_w[..., None] * sdiv(D[..., None], RGB_w) + 1 - D[..., None]) * RGB

return cast(NDArrayFloat, RGB_c)
return cast("NDArrayFloat", RGB_c)


def full_chromatic_adaptation_inverse(
@@ -825,7 +825,7 @@ def full_chromatic_adaptation_inverse(
with sdiv_mode():
RGB_c = RGB / (Y_w[..., None] * sdiv(D[..., None], RGB_w) + 1 - D[..., None])

return cast(NDArrayFloat, RGB_c)
return cast("NDArrayFloat", RGB_c)


def RGB_to_rgb(RGB: ArrayLike) -> NDArrayFloat:
8 changes: 4 additions & 4 deletions colour/appearance/hunt.py
Original file line number Diff line number Diff line change
@@ -506,8 +506,8 @@ def XYZ_to_Hunt(
# Computing the correlate of *brightness* :math:`Q`.
# -------------------------------------------------------------------------
# Computing achromatic signal :math:`A`.
A = achromatic_signal(cast(NDArrayFloat, L_AS), S_p, S_w_p, N_bb, A_a)
A_w = achromatic_signal(cast(NDArrayFloat, L_AS), S_w_p, S_w_p, N_bb, A_aw)
A = achromatic_signal(cast("NDArrayFloat", L_AS), S_p, S_w_p, N_bb, A_a)
A_w = achromatic_signal(cast("NDArrayFloat", L_AS), S_w_p, S_w_p, N_bb, A_aw)

Q = brightness_correlate(A, A_w, M, surround.N_b)
brightness_w = brightness_correlate(A_w, A_w, M_w, surround.N_b)
@@ -742,9 +742,9 @@ def chromatic_adaptation(
# Computing chromatic adaptation factors.
if not discount_illuminant:
L_A_p = spow(L_A, 1 / 3)
F_rgb = cast(NDArrayFloat, (1 + L_A_p + h_rgb) / (1 + L_A_p + (1 / h_rgb)))
F_rgb = cast("NDArrayFloat", (1 + L_A_p + h_rgb) / (1 + L_A_p + (1 / h_rgb)))
else:
F_rgb = ones(cast(NDArrayFloat, h_rgb).shape)
F_rgb = ones(cast("NDArrayFloat", h_rgb).shape)

# Computing Helson-Judd effect parameters.
if helson_judd_effect:
2 changes: 1 addition & 1 deletion colour/appearance/nayatani95.py
Original file line number Diff line number Diff line change
@@ -787,7 +787,7 @@ def chromatic_strength_function(

theta = np.radians(theta)

E_s = cast(NDArrayFloat, 0.9394)
E_s = cast("NDArrayFloat", 0.9394)
E_s += -0.2478 * np.sin(1 * theta)
E_s += -0.0743 * np.sin(2 * theta)
E_s += +0.0666 * np.sin(3 * theta)
16 changes: 8 additions & 8 deletions colour/characterisation/aces_it.py
Original file line number Diff line number Diff line change
@@ -390,7 +390,7 @@ def generate_illuminants_rawtoaces_v1() -> CanonicalMapping:

# Blackbody from 1000K to 4000K.
for i in np.arange(1000, 4000, 500):
sd = sd_blackbody(cast(float, i), SPECTRAL_SHAPE_RAWTOACES)
sd = sd_blackbody(cast("float", i), SPECTRAL_SHAPE_RAWTOACES)
illuminants[sd.name] = sd

# A.M.P.A.S. variant of ISO 7589 Studio Tungsten.
@@ -498,7 +498,7 @@ def best_illuminant(
sse = sse_c
illuminant_b = illuminant

return cast(SpectralDistribution, illuminant_b)
return cast("SpectralDistribution", illuminant_b)


def normalise_illuminant(
@@ -734,9 +734,9 @@ def whitepoint_preserving_matrix(
return M


def optimisation_factory_rawtoaces_v1() -> (
Tuple[NDArrayFloat, Callable, Callable, Callable]
):
def optimisation_factory_rawtoaces_v1() -> Tuple[
NDArrayFloat, Callable, Callable, Callable
]:
"""
Produce the objective function and *CIE XYZ* colourspace to optimisation
colourspace/colour model function according to *RAW to ACES* v1.
@@ -861,9 +861,9 @@ def finaliser_function(M: ArrayLike) -> NDArrayFloat:
)


def optimisation_factory_Oklab_15() -> (
Tuple[NDArrayFloat, Callable, Callable, Callable]
):
def optimisation_factory_Oklab_15() -> Tuple[
NDArrayFloat, Callable, Callable, Callable
]:
"""
Produce the objective function and *CIE XYZ* colourspace to optimisation
colourspace/colour model function based on the *Oklab* colourspace.
23 changes: 11 additions & 12 deletions colour/colorimetry/spectrum.py
Original file line number Diff line number Diff line change
@@ -394,7 +394,7 @@ def __contains__(self, wavelength: ArrayLike) -> bool:
False
"""

decimals = np.finfo(cast(Any, DTYPE_FLOAT_DEFAULT)).precision
decimals = np.finfo(cast("Any", DTYPE_FLOAT_DEFAULT)).precision

return bool(
np.all(
@@ -531,7 +531,7 @@ def range(self, dtype: Type[DTypeFloat] | None = None) -> NDArrayFloat:
_CACHE_SHAPE_RANGE[hash_key] = range_

if interval_effective != self._interval:
self._interval = cast(float, interval_effective)
self._interval = cast("float", interval_effective)
runtime_warning(
f'"{(start, end, interval)}" shape could not be honoured, '
f'using "{self}"!'
@@ -717,7 +717,7 @@ def _on_domain_changed(
"""Invalidate *sd._shape* when *sd._domain* is changed."""

if name == "_domain":
sd._shape = None # noqa: SLF001
sd._shape = None

return value

@@ -1883,8 +1883,7 @@ def display_labels(self, value: Sequence) -> None:

attest(
is_iterable(value),
f'"display_labels" property: "{value}" is not an "iterable" like '
f"object!",
f'"display_labels" property: "{value}" is not an "iterable" like object!',
)

attest(
@@ -1899,7 +1898,7 @@ def display_labels(self, value: Sequence) -> None:

self._display_labels = [str(label) for label in value]
for i, signal in enumerate(self.signals.values()):
cast(SpectralDistribution, signal).display_name = self._display_labels[i]
cast("SpectralDistribution", signal).display_name = self._display_labels[i]

@property
def wavelengths(self) -> NDArrayFloat:
@@ -2217,7 +2216,7 @@ def interpolate(
"""

for signal in self.signals.values():
cast(SpectralDistribution, signal).interpolate(
cast("SpectralDistribution", signal).interpolate(
shape, interpolator, interpolator_kwargs
)

@@ -2303,7 +2302,7 @@ def extrapolate(
"""

for signal in self.signals.values():
cast(SpectralDistribution, signal).extrapolate(
cast("SpectralDistribution", signal).extrapolate(
shape, extrapolator, extrapolator_kwargs
)

@@ -2451,7 +2450,7 @@ def align(
"""

for signal in self.signals.values():
cast(SpectralDistribution, signal).align(
cast("SpectralDistribution", signal).align(
shape,
interpolator,
interpolator_kwargs,
@@ -2536,7 +2535,7 @@ def trim(self, shape: SpectralShape) -> Self:
"""

for signal in self.signals.values():
cast(SpectralDistribution, signal).trim(shape)
cast("SpectralDistribution", signal).trim(shape)

return self

@@ -2585,7 +2584,7 @@ def normalise(self, factor: Real = 1) -> Self:
"""

for signal in self.signals.values():
cast(SpectralDistribution, signal).normalise(factor)
cast("SpectralDistribution", signal).normalise(factor)

return self

@@ -2639,7 +2638,7 @@ def to_sds(self) -> List[SpectralDistribution]:
"""

return [
cast(SpectralDistribution, signal.copy())
cast("SpectralDistribution", signal.copy())
for signal in self.signals.values()
]

7 changes: 3 additions & 4 deletions colour/colorimetry/tristimulus_values.py
Original file line number Diff line number Diff line change
@@ -691,7 +691,7 @@ def sd_to_XYZ_integration(
"A spectral shape must be explicitly passed with a spectral data array!",
)

shape = cast(SpectralShape, shape)
shape = cast("SpectralShape", shape)

R = as_float_array(sd)
shape_R = R.shape
@@ -719,7 +719,7 @@ def sd_to_XYZ_integration(
d_w = cmfs.shape.interval

with sdiv_mode():
k = cast(Real, optional(k, sdiv(100, (np.sum(XYZ_b[..., 1] * S) * d_w))))
k = cast("Real", optional(k, sdiv(100, (np.sum(XYZ_b[..., 1] * S) * d_w))))

XYZ = k * np.dot(R * S, XYZ_b) * d_w

@@ -1274,8 +1274,7 @@ def sd_to_XYZ(

if isinstance(sd, MultiSpectralDistributions):
runtime_warning(
"A multi-spectral distributions was passed, enforcing integration "
"method!"
"A multi-spectral distributions was passed, enforcing integration method!"
)
function = sd_to_XYZ_integration
else:
6 changes: 3 additions & 3 deletions colour/constants/common.py
Original file line number Diff line number Diff line change
@@ -45,14 +45,14 @@
int.
"""

EPSILON: float = cast(float, np.finfo(np.double).eps)
EPSILON: float = cast("float", np.finfo(np.double).eps)
"""
Default epsilon value for tolerance and singularities avoidance in various
computations.
"""

DTYPE_INT_DEFAULT: Type[np.int32 | np.int64] = cast(
Type[np.int32 | np.int64],
"Type[np.int32 | np.int64]",
np.sctypeDict.get(
os.environ.get("COLOUR_SCIENCE__DEFAULT_INT_DTYPE", "int64"), np.int64
),
@@ -61,7 +61,7 @@


DTYPE_FLOAT_DEFAULT: Type[DTypeFloat] = cast(
Type[DTypeFloat],
"Type[DTypeFloat]",
np.sctypeDict.get(
os.environ.get("COLOUR_SCIENCE__DEFAULT_FLOAT_DTYPE", "float64"),
np.float64,
Loading