Skip to content

Commit 383f312

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 413f5ee commit 383f312

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+269
-309
lines changed

colour/algebra/common.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,16 @@
7171
"""
7272

7373

74-
def get_sdiv_mode() -> (
75-
Literal[
76-
"Numpy",
77-
"Ignore",
78-
"Warning",
79-
"Raise",
80-
"Ignore Zero Conversion",
81-
"Warning Zero Conversion",
82-
"Ignore Limit Conversion",
83-
"Warning Limit Conversion",
84-
]
85-
):
74+
def get_sdiv_mode() -> Literal[
75+
"Numpy",
76+
"Ignore",
77+
"Warning",
78+
"Raise",
79+
"Ignore Zero Conversion",
80+
"Warning Zero Conversion",
81+
"Ignore Limit Conversion",
82+
"Warning Limit Conversion",
83+
]:
8684
"""
8785
Return *Colour* safe division mode.
8886
@@ -142,16 +140,7 @@ def set_sdiv_mode(
142140
global _SDIV_MODE # noqa: PLW0603
143141

144142
_SDIV_MODE = cast(
145-
Literal[
146-
"Numpy",
147-
"Ignore",
148-
"Warning",
149-
"Raise",
150-
"Ignore Zero Conversion",
151-
"Warning Zero Conversion",
152-
"Ignore Limit Conversion",
153-
"Warning Limit Conversion",
154-
],
143+
"Literal['Numpy', 'Ignore', 'Warning', 'Raise', 'Ignore Zero Conversion', 'Warning Zero Conversion', 'Ignore Limit Conversion', 'Warning Limit Conversion']",
155144
validate_method(
156145
mode,
157146
(

colour/algebra/interpolation.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,7 @@ class NearestNeighbourInterpolator(KernelInterpolator):
758758

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

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

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

853-
value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype))
852+
value = cast("NDArrayFloat", np.atleast_1d(value).astype(self._dtype))
854853

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

886-
value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype))
885+
value = cast("NDArrayFloat", np.atleast_1d(value).astype(self._dtype))
887886

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

11371136
attest(
11381137
len(value) >= 6,
1139-
'"y" dependent variable values count must be equal to or '
1140-
"greater than 6!",
1138+
'"y" dependent variable values count must be equal to or greater than 6!',
11411139
)
11421140

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

1426-
value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype))
1424+
value = cast("NDArrayFloat", np.atleast_1d(value).astype(self._dtype))
14271425

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

1459-
value = cast(NDArrayFloat, np.atleast_1d(value).astype(self._dtype))
1457+
value = cast("NDArrayFloat", np.atleast_1d(value).astype(self._dtype))
14601458

14611459
attest(
14621460
value.ndim == 1,

colour/algebra/tests/test_interpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@
483483
)
484484

485485
LUT_TABLE: NDArrayFloat = cast(
486-
LUT3D,
486+
"LUT3D",
487487
read_LUT(
488488
os.path.join(
489489
os.path.dirname(__file__),

colour/appearance/ciecam02.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ def full_chromatic_adaptation_forward(
777777
with sdiv_mode():
778778
RGB_c = (Y_w[..., None] * sdiv(D[..., None], RGB_w) + 1 - D[..., None]) * RGB
779779

780-
return cast(NDArrayFloat, RGB_c)
780+
return cast("NDArrayFloat", RGB_c)
781781

782782

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

828-
return cast(NDArrayFloat, RGB_c)
828+
return cast("NDArrayFloat", RGB_c)
829829

830830

831831
def RGB_to_rgb(RGB: ArrayLike) -> NDArrayFloat:

colour/appearance/hunt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ def XYZ_to_Hunt(
506506
# Computing the correlate of *brightness* :math:`Q`.
507507
# -------------------------------------------------------------------------
508508
# Computing achromatic signal :math:`A`.
509-
A = achromatic_signal(cast(NDArrayFloat, L_AS), S_p, S_w_p, N_bb, A_a)
510-
A_w = achromatic_signal(cast(NDArrayFloat, L_AS), S_w_p, S_w_p, N_bb, A_aw)
509+
A = achromatic_signal(cast("NDArrayFloat", L_AS), S_p, S_w_p, N_bb, A_a)
510+
A_w = achromatic_signal(cast("NDArrayFloat", L_AS), S_w_p, S_w_p, N_bb, A_aw)
511511

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

749749
# Computing Helson-Judd effect parameters.
750750
if helson_judd_effect:

colour/appearance/nayatani95.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ def chromatic_strength_function(
787787

788788
theta = np.radians(theta)
789789

790-
E_s = cast(NDArrayFloat, 0.9394)
790+
E_s = cast("NDArrayFloat", 0.9394)
791791
E_s += -0.2478 * np.sin(1 * theta)
792792
E_s += -0.0743 * np.sin(2 * theta)
793793
E_s += +0.0666 * np.sin(3 * theta)

colour/characterisation/aces_it.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def generate_illuminants_rawtoaces_v1() -> CanonicalMapping:
389389

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

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

500-
return cast(SpectralDistribution, illuminant_b)
500+
return cast("SpectralDistribution", illuminant_b)
501501

502502

503503
def normalise_illuminant(
@@ -733,9 +733,9 @@ def whitepoint_preserving_matrix(
733733
return M
734734

735735

736-
def optimisation_factory_rawtoaces_v1() -> (
737-
Tuple[NDArrayFloat, Callable, Callable, Callable]
738-
):
736+
def optimisation_factory_rawtoaces_v1() -> Tuple[
737+
NDArrayFloat, Callable, Callable, Callable
738+
]:
739739
"""
740740
Produce the objective function and *CIE XYZ* colourspace to optimisation
741741
colourspace/colour model function according to *RAW to ACES* v1.
@@ -862,9 +862,9 @@ def finaliser_function(M: ArrayLike) -> NDArrayFloat:
862862
)
863863

864864

865-
def optimisation_factory_Oklab_15() -> (
866-
Tuple[NDArrayFloat, Callable, Callable, Callable]
867-
):
865+
def optimisation_factory_Oklab_15() -> Tuple[
866+
NDArrayFloat, Callable, Callable, Callable
867+
]:
868868
"""
869869
Produce the objective function and *CIE XYZ* colourspace to optimisation
870870
colourspace/colour model function based on the *Oklab* colourspace.

colour/colorimetry/spectrum.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def __contains__(self, wavelength: ArrayLike) -> bool:
394394
False
395395
"""
396396

397-
decimals = np.finfo(cast(Any, DTYPE_FLOAT_DEFAULT)).precision
397+
decimals = np.finfo(cast("Any", DTYPE_FLOAT_DEFAULT)).precision
398398

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

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

719719
if name == "_domain":
720-
sd._shape = None # noqa: SLF001
720+
sd._shape = None
721721

722722
return value
723723

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

18841884
attest(
18851885
is_iterable(value),
1886-
f'"display_labels" property: "{value}" is not an "iterable" like '
1887-
f"object!",
1886+
f'"display_labels" property: "{value}" is not an "iterable" like object!',
18881887
)
18891888

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

19001899
self._display_labels = [str(label) for label in value]
19011900
for i, signal in enumerate(self.signals.values()):
1902-
cast(SpectralDistribution, signal).display_name = self._display_labels[i]
1901+
cast("SpectralDistribution", signal).display_name = self._display_labels[i]
19031902

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

22192218
for signal in self.signals.values():
2220-
cast(SpectralDistribution, signal).interpolate(
2219+
cast("SpectralDistribution", signal).interpolate(
22212220
shape, interpolator, interpolator_kwargs
22222221
)
22232222

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

23052304
for signal in self.signals.values():
2306-
cast(SpectralDistribution, signal).extrapolate(
2305+
cast("SpectralDistribution", signal).extrapolate(
23072306
shape, extrapolator, extrapolator_kwargs
23082307
)
23092308

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

24532452
for signal in self.signals.values():
2454-
cast(SpectralDistribution, signal).align(
2453+
cast("SpectralDistribution", signal).align(
24552454
shape,
24562455
interpolator,
24572456
interpolator_kwargs,
@@ -2536,7 +2535,7 @@ def trim(self, shape: SpectralShape) -> Self:
25362535
"""
25372536

25382537
for signal in self.signals.values():
2539-
cast(SpectralDistribution, signal).trim(shape)
2538+
cast("SpectralDistribution", signal).trim(shape)
25402539

25412540
return self
25422541

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

25872586
for signal in self.signals.values():
2588-
cast(SpectralDistribution, signal).normalise(factor)
2587+
cast("SpectralDistribution", signal).normalise(factor)
25892588

25902589
return self
25912590

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

26412640
return [
2642-
cast(SpectralDistribution, signal.copy())
2641+
cast("SpectralDistribution", signal.copy())
26432642
for signal in self.signals.values()
26442643
]
26452644

colour/colorimetry/tristimulus_values.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def sd_to_XYZ_integration(
691691
"A spectral shape must be explicitly passed with a spectral data array!",
692692
)
693693

694-
shape = cast(SpectralShape, shape)
694+
shape = cast("SpectralShape", shape)
695695

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

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

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

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

12751275
if isinstance(sd, MultiSpectralDistributions):
12761276
runtime_warning(
1277-
"A multi-spectral distributions was passed, enforcing integration "
1278-
"method!"
1277+
"A multi-spectral distributions was passed, enforcing integration method!"
12791278
)
12801279
function = sd_to_XYZ_integration
12811280
else:

colour/constants/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
int.
4646
"""
4747

48-
EPSILON: float = cast(float, np.finfo(np.double).eps)
48+
EPSILON: float = cast("float", np.finfo(np.double).eps)
4949
"""
5050
Default epsilon value for tolerance and singularities avoidance in various
5151
computations.
5252
"""
5353

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

6262

6363
DTYPE_FLOAT_DEFAULT: Type[DTypeFloat] = cast(
64-
Type[DTypeFloat],
64+
"Type[DTypeFloat]",
6565
np.sctypeDict.get(
6666
os.environ.get("COLOUR_SCIENCE__DEFAULT_FLOAT_DTYPE", "float64"),
6767
np.float64,

colour/continuous/multi_signals.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ def arithmetical_operation(
11831183
):
11841184
signal_a.arithmetical_operation(signal_b, operation, True)
11851185
else:
1186-
a = as_float_array(cast(ArrayLike, a))
1186+
a = as_float_array(cast("ArrayLike", a))
11871187

11881188
attest(
11891189
a.ndim in range(3),
@@ -1444,7 +1444,7 @@ def multi_signals_unpack_data(
14441444
elif issubclass(type(data), Sequence) or isinstance(
14451445
data, (tuple, list, np.ndarray, Iterator, ValuesView)
14461446
):
1447-
data_sequence = list(cast(Sequence, data))
1447+
data_sequence = list(cast("Sequence", data))
14481448

14491449
is_signal = True
14501450
for i in data_sequence:
@@ -1470,7 +1470,7 @@ def multi_signals_unpack_data(
14701470
for i, range_unpacked in enumerate(data_array):
14711471
signals[str(i)] = signal_type(range_unpacked, domain, **settings)
14721472
elif issubclass(type(data), Mapping) or isinstance(data, dict):
1473-
data_mapping = dict(cast(Mapping, data))
1473+
data_mapping = dict(cast("Mapping", data))
14741474

14751475
is_signal = all(isinstance(i, Signal) for i in data_mapping.values())
14761476

@@ -1510,8 +1510,7 @@ def multi_signals_unpack_data(
15101510
for signal in signals.values():
15111511
attest(
15121512
len(domain_array) == len(signal.domain),
1513-
'User "domain" length is not compatible with unpacked '
1514-
'"signals"!',
1513+
'User "domain" length is not compatible with unpacked "signals"!',
15151514
)
15161515

15171516
signal.domain = domain_array

0 commit comments

Comments
 (0)