diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9e240b295..0777cf850 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/colour/algebra/common.py b/colour/algebra/common.py index b124d1709..d699b80b4 100644 --- a/colour/algebra/common.py +++ b/colour/algebra/common.py @@ -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, ( diff --git a/colour/algebra/interpolation.py b/colour/algebra/interpolation.py index aa4f321f1..b932a8951 100644 --- a/colour/algebra/interpolation.py +++ b/colour/algebra/interpolation.py @@ -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, diff --git a/colour/algebra/tests/test_interpolation.py b/colour/algebra/tests/test_interpolation.py index 1d4281ca3..b4f8e86f0 100644 --- a/colour/algebra/tests/test_interpolation.py +++ b/colour/algebra/tests/test_interpolation.py @@ -483,7 +483,7 @@ ) LUT_TABLE: NDArrayFloat = cast( - LUT3D, + "LUT3D", read_LUT( os.path.join( os.path.dirname(__file__), diff --git a/colour/appearance/ciecam02.py b/colour/appearance/ciecam02.py index 3a03e8d24..0b94391a9 100644 --- a/colour/appearance/ciecam02.py +++ b/colour/appearance/ciecam02.py @@ -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: diff --git a/colour/appearance/hunt.py b/colour/appearance/hunt.py index 4f5105088..6a34f1fbb 100644 --- a/colour/appearance/hunt.py +++ b/colour/appearance/hunt.py @@ -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: diff --git a/colour/appearance/nayatani95.py b/colour/appearance/nayatani95.py index d7da4e321..157f2a2a4 100644 --- a/colour/appearance/nayatani95.py +++ b/colour/appearance/nayatani95.py @@ -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) diff --git a/colour/characterisation/aces_it.py b/colour/characterisation/aces_it.py index 037a1cb19..10acf9221 100644 --- a/colour/characterisation/aces_it.py +++ b/colour/characterisation/aces_it.py @@ -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. diff --git a/colour/colorimetry/spectrum.py b/colour/colorimetry/spectrum.py index 15fd3ad9e..f043bc3f0 100644 --- a/colour/colorimetry/spectrum.py +++ b/colour/colorimetry/spectrum.py @@ -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() ] diff --git a/colour/colorimetry/tristimulus_values.py b/colour/colorimetry/tristimulus_values.py index e9ac620aa..342d9d0b4 100644 --- a/colour/colorimetry/tristimulus_values.py +++ b/colour/colorimetry/tristimulus_values.py @@ -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: diff --git a/colour/constants/common.py b/colour/constants/common.py index 44e7c403e..c088779f1 100644 --- a/colour/constants/common.py +++ b/colour/constants/common.py @@ -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, diff --git a/colour/continuous/multi_signals.py b/colour/continuous/multi_signals.py index 925c68699..9616938f9 100644 --- a/colour/continuous/multi_signals.py +++ b/colour/continuous/multi_signals.py @@ -1183,7 +1183,7 @@ def arithmetical_operation( ): signal_a.arithmetical_operation(signal_b, operation, True) else: - a = as_float_array(cast(ArrayLike, a)) + a = as_float_array(cast("ArrayLike", a)) attest( a.ndim in range(3), @@ -1444,7 +1444,7 @@ def multi_signals_unpack_data( elif issubclass(type(data), Sequence) or isinstance( data, (tuple, list, np.ndarray, Iterator, ValuesView) ): - data_sequence = list(cast(Sequence, data)) + data_sequence = list(cast("Sequence", data)) is_signal = True for i in data_sequence: @@ -1470,7 +1470,7 @@ def multi_signals_unpack_data( for i, range_unpacked in enumerate(data_array): signals[str(i)] = signal_type(range_unpacked, domain, **settings) elif issubclass(type(data), Mapping) or isinstance(data, dict): - data_mapping = dict(cast(Mapping, data)) + data_mapping = dict(cast("Mapping", data)) is_signal = all(isinstance(i, Signal) for i in data_mapping.values()) @@ -1510,8 +1510,7 @@ def multi_signals_unpack_data( for signal in signals.values(): attest( len(domain_array) == len(signal.domain), - 'User "domain" length is not compatible with unpacked ' - '"signals"!', + 'User "domain" length is not compatible with unpacked "signals"!', ) signal.domain = domain_array diff --git a/colour/continuous/signal.py b/colour/continuous/signal.py index 349cf3d79..96b597b23 100644 --- a/colour/continuous/signal.py +++ b/colour/continuous/signal.py @@ -556,9 +556,9 @@ def _undefined_function( raise ValueError(error) - self._function = cast(Callable, _undefined_function) + self._function = cast("Callable", _undefined_function) - return cast(Callable, self._function) + return cast("Callable", self._function) @ndarray_copy_enable(False) def __str__(self) -> str: @@ -1174,7 +1174,7 @@ def signal_unpack_data( data, (tuple, list, np.ndarray, Iterator, ValuesView) ): data_array = ( - tsplit(list(cast(Sequence, data))) + tsplit(list(cast("Sequence", data))) if not isinstance(data, np.ndarray) else data ) @@ -1187,7 +1187,7 @@ def signal_unpack_data( ) elif issubclass(type(data), Mapping) or isinstance(data, dict): # pyright: ignore domain_unpacked, range_unpacked = tsplit( - sorted(cast(Mapping, data).items()) + sorted(cast("Mapping", data).items()) ) elif is_pandas_installed() and isinstance(data, Series): domain_unpacked = as_float_array(data.index.values, dtype) # pyright: ignore diff --git a/colour/examples/algebra/examples_interpolation.py b/colour/examples/algebra/examples_interpolation.py index be4ae3757..5eb953b43 100644 --- a/colour/examples/algebra/examples_interpolation.py +++ b/colour/examples/algebra/examples_interpolation.py @@ -171,7 +171,7 @@ "iridas_cube", "Colour_Correct.cube", ) -table = cast(colour.LUT3D, colour.read_LUT(path)).table +table = cast("colour.LUT3D", colour.read_LUT(path)).table print(colour.table_interpolation(V_xyz, table, method="Trilinear")) print(colour.algebra.table_interpolation_trilinear(V_xyz, table)) diff --git a/colour/examples/characterisation/examples_aces_it.py b/colour/examples/characterisation/examples_aces_it.py index 190d2fd6b..e12dbac04 100644 --- a/colour/examples/characterisation/examples_aces_it.py +++ b/colour/examples/characterisation/examples_aces_it.py @@ -63,7 +63,7 @@ print( colour.matrix_idt( - cast(colour.characterisation.RGB_CameraSensitivities, sensitivities), + cast("colour.characterisation.RGB_CameraSensitivities", sensitivities), illuminant, ) ) @@ -74,7 +74,7 @@ ) M, RGB_w = colour.matrix_idt( # pyright: ignore - cast(colour.characterisation.RGB_CameraSensitivities, sensitivities), + cast("colour.characterisation.RGB_CameraSensitivities", sensitivities), illuminant, optimisation_factory=colour.characterisation.optimisation_factory_Oklab_15, ) diff --git a/colour/examples/models/examples_models.py b/colour/examples/models/examples_models.py index 0de71d373..ee866b7e7 100644 --- a/colour/examples/models/examples_models.py +++ b/colour/examples/models/examples_models.py @@ -413,8 +413,7 @@ Lab = np.array([0.51634019, 0.15469500, 0.06289579]) message_box( - f'Converting to "CIE XYZ" tristimulus values from "Oklab" colourspace:\n\n' - f"\t{Lab}" + f'Converting to "CIE XYZ" tristimulus values from "Oklab" colourspace:\n\n\t{Lab}' ) print(colour.Oklab_to_XYZ(Lab)) diff --git a/colour/examples/models/examples_rgb.py b/colour/examples/models/examples_rgb.py index 8660ea802..e2e77fe84 100644 --- a/colour/examples/models/examples_rgb.py +++ b/colour/examples/models/examples_rgb.py @@ -75,8 +75,7 @@ print("\n") message_box( - f"Transfer Characteristics: " - f"{list(colour.TRANSFER_CHARACTERISTICS_ITUTH273.keys())}" + f"Transfer Characteristics: {list(colour.TRANSFER_CHARACTERISTICS_ITUTH273.keys())}" ) colour.models.describe_video_signal_transfer_characteristics(1) diff --git a/colour/examples/plotting/examples_colorimetry_plots.py b/colour/examples/plotting/examples_colorimetry_plots.py index aa958865d..5b7c89045 100644 --- a/colour/examples/plotting/examples_colorimetry_plots.py +++ b/colour/examples/plotting/examples_colorimetry_plots.py @@ -36,8 +36,7 @@ print("\n") message_box( - 'Plotting "CIE Standard Illuminant "A", "B", and "C" with their ' - "normalised colours." + 'Plotting "CIE Standard Illuminant "A", "B", and "C" with their normalised colours.' ) plot_multi_illuminant_sds( ["A", "B", "C"], diff --git a/colour/examples/plotting/examples_models_plots.py b/colour/examples/plotting/examples_models_plots.py index c0b99df99..41a344e23 100644 --- a/colour/examples/plotting/examples_models_plots.py +++ b/colour/examples/plotting/examples_models_plots.py @@ -87,8 +87,7 @@ print("\n") message_box( - 'Plotting a single custom "RGB" colourspace in the ' - '"CIE 1931 Chromaticity Diagram".' + 'Plotting a single custom "RGB" colourspace in the "CIE 1931 Chromaticity Diagram".' ) AWFUL_RGB = colour.RGB_Colourspace( "Awful RGB", @@ -107,21 +106,18 @@ print("\n") message_box( - 'Plotting a single "RGB" colourspace encoding colour component transfer ' - "function." + 'Plotting a single "RGB" colourspace encoding colour component transfer function.' ) plot_single_cctf("ITU-R BT.709") print("\n") message_box( - 'Plotting multiple "RGB" colourspaces encoding colour component transfer ' - "functions." + 'Plotting multiple "RGB" colourspaces encoding colour component transfer functions.' ) plot_multi_cctfs(["ITU-R BT.709", "sRGB"]) message_box( - 'Plotting multiple "RGB" colourspaces decoding colour component transfer ' - "functions." + 'Plotting multiple "RGB" colourspaces decoding colour component transfer functions.' ) plot_multi_cctfs(["ACES2065-1", "ProPhoto RGB"], cctf_decoding=True) diff --git a/colour/examples/quality/examples_cfi.py b/colour/examples/quality/examples_cfi.py index 1fb6c56fa..bb58dce03 100644 --- a/colour/examples/quality/examples_cfi.py +++ b/colour/examples/quality/examples_cfi.py @@ -21,8 +21,7 @@ print("\n") message_box( - 'Computing "F2" illuminant "Colour Fidelity Index" (CFI) with detailed ' - "output data." + 'Computing "F2" illuminant "Colour Fidelity Index" (CFI) with detailed output data.' ) pprint( colour.colour_fidelity_index(colour.SDS_ILLUMINANTS["FL2"], additional_data=True) diff --git a/colour/examples/volume/examples_rgb.py b/colour/examples/volume/examples_rgb.py index d4125227f..855f86fd6 100644 --- a/colour/examples/volume/examples_rgb.py +++ b/colour/examples/volume/examples_rgb.py @@ -16,8 +16,7 @@ samples = int(10e4) message_box( - f'Computing the "ProPhoto RGB" RGB colourspace volume using {samples} ' - f"samples." + f'Computing the "ProPhoto RGB" RGB colourspace volume using {samples} samples.' ) print( colour.RGB_colourspace_volume_MonteCarlo( diff --git a/colour/geometry/ellipse.py b/colour/geometry/ellipse.py index 75c05c50e..935636cf9 100644 --- a/colour/geometry/ellipse.py +++ b/colour/geometry/ellipse.py @@ -274,7 +274,7 @@ def ellipse_fitting_Halir1998(a: ArrayLike) -> NDArrayFloat: A1 = v[:, np.nonzero(4 * v[0, :] * v[2, :] - v[1, :] ** 2 > 0)[0]] A2 = np.dot(T, A1) - return cast(NDArrayFloat, np.ravel([A1, A2])) + return cast("NDArrayFloat", np.ravel([A1, A2])) ELLIPSE_FITTING_METHODS: CanonicalMapping = CanonicalMapping( diff --git a/colour/geometry/primitives.py b/colour/geometry/primitives.py index 00ff2b0a4..7d5438a26 100644 --- a/colour/geometry/primitives.py +++ b/colour/geometry/primitives.py @@ -196,13 +196,13 @@ def primitive_grid( sign = -1 if "-" in axis else 1 positions = np.roll(positions, shift, -1) - normals = cast(NDArrayFloat, np.roll(normals, shift, -1)) * sign + normals = cast("NDArrayFloat", np.roll(normals, shift, -1)) * sign vertex_colours = np.ravel(positions) vertex_colours = np.hstack( [ np.reshape( np.interp( - cast(NDArrayFloat, vertex_colours), + cast("NDArrayFloat", vertex_colours), (np.min(vertex_colours), np.max(vertex_colours)), (0, 1), ), @@ -428,7 +428,7 @@ def primitive_cube( [ np.reshape( np.interp( - cast(NDArrayFloat, vertex_colours), + cast("NDArrayFloat", vertex_colours), (np.min(vertex_colours), np.max(vertex_colours)), (0, 1), ), diff --git a/colour/geometry/section.py b/colour/geometry/section.py index 81ce2128e..8c13fbdc0 100644 --- a/colour/geometry/section.py +++ b/colour/geometry/section.py @@ -86,7 +86,7 @@ def edges_to_chord(edges: ArrayLike, index: int = 0) -> NDArrayFloat: [-0. , -0.5, 0. ]]) """ - edge_list = cast(List[List[float]], as_float_array(edges).tolist()) + edge_list = cast("List[List[float]]", as_float_array(edges).tolist()) edges_ordered = [edge_list.pop(index)] segment = np.array(edges_ordered[0][1]) diff --git a/colour/graph/conversion.py b/colour/graph/conversion.py index 772839c23..1980670d1 100644 --- a/colour/graph/conversion.py +++ b/colour/graph/conversion.py @@ -284,9 +284,9 @@ def CIECAM02_to_JMh_CIECAM02( return tstack( [ - cast(NDArrayFloat, specification.J), - cast(NDArrayFloat, specification.M), - cast(NDArrayFloat, specification.h), + cast("NDArrayFloat", specification.J), + cast("NDArrayFloat", specification.M), + cast("NDArrayFloat", specification.h), ] ) @@ -1098,7 +1098,7 @@ def _conversion_path(source: str, target: str) -> List[Callable]: # Updating the :attr:`CONVERSION_GRAPH` attributes. colour.graph.CONVERSION_GRAPH = CONVERSION_GRAPH = _build_graph() - path = nx.shortest_path(cast(nx.DiGraph, CONVERSION_GRAPH), source, target) + path = nx.shortest_path(cast("nx.DiGraph", CONVERSION_GRAPH), source, target) return [ CONVERSION_GRAPH.get_edge_data(a, b)["conversion_function"] # pyright: ignore diff --git a/colour/io/fichet2021.py b/colour/io/fichet2021.py index 717a561f3..2f3990667 100644 --- a/colour/io/fichet2021.py +++ b/colour/io/fichet2021.py @@ -307,7 +307,7 @@ class Specification_Fichet2021: References ---------- :cite:`Fichet2021` - """ # noqa: D405, D407, D410, D411 + """ path: str | None = field(default_factory=lambda: None) components: defaultdict = field(default_factory=lambda: defaultdict(dict)) @@ -848,13 +848,13 @@ def write_spectral_image_Fichet2021( for i, wavelength in enumerate(wavelengths): component_type = str(component)[0] if component_type == "S": # Emissive Component Type # noqa: SIM114 - channel_name = f'{component}.{str(wavelength).replace(".", ",")}nm' + channel_name = f"{component}.{str(wavelength).replace('.', ',')}nm" elif component_type == "T": # Reflectance et al. Component Type - channel_name = f'{component}.{str(wavelength).replace(".", ",")}nm' + channel_name = f"{component}.{str(wavelength).replace('.', ',')}nm" else: # Bi-spectral Component Type channel_name = ( - f'T.{str(component).replace(".", ",")}nm.' - f'{str(wavelength).replace(".", ",")}nm' + f"T.{str(component).replace('.', ',')}nm." + f"{str(wavelength).replace('.', ',')}nm" ) channels[channel_name] = values[..., i] diff --git a/colour/io/image.py b/colour/io/image.py index 499e11b7e..3b0c4340b 100644 --- a/colour/io/image.py +++ b/colour/io/image.py @@ -176,7 +176,7 @@ def add_attributes_to_image_specification_OpenImageIO( ... ) # doctest: +SKIP >>> image_specification.extra_attribs[0].value # doctest: +SKIP 'none' - """ # noqa: D405, D407, D410, D411 + """ for attribute in attributes: name = str(attribute.name) @@ -234,11 +234,11 @@ def image_specification_OpenImageIO( ... 1920, 1080, 3, "float16", [compression] ... ) # doctest: +SKIP - """ # noqa: D405, D407, D410, D411 + """ from OpenImageIO import ImageSpec # pyright: ignore - attributes = cast(list, optional(attributes, [])) + attributes = cast("list", optional(attributes, [])) bit_depth_specification = MAPPING_BIT_DEPTH[bit_depth] @@ -439,7 +439,7 @@ def read_image_OpenImageIO( image_input.close() image = np.reshape(np.array(image, dtype=bit_depth_specification.numpy), shape) - image = cast(NDArrayReal, np.squeeze(image)) + image = cast("NDArrayReal", np.squeeze(image)) if additional_data: extra_attributes = [ @@ -687,14 +687,14 @@ def write_image_OpenImageIO( ... Image_Specification_Attribute("compression", "none"), ... ] ... write_image_OpenImageIO(image, path, attributes=attributes) - """ # noqa: D405, D407, D410, D411 + """ from OpenImageIO import ImageOutput # pyright: ignore image = as_float_array(image) path = str(path) - attributes = cast(list, optional(attributes, [])) + attributes = cast("list", optional(attributes, [])) bit_depth_specification = MAPPING_BIT_DEPTH[bit_depth] @@ -901,7 +901,7 @@ def write_image( >>> write_image(image, path, bit_depth="uint8", attributes=[compression]) ... # doctest: +SKIP True - """ # noqa: D405, D407, D410, D411, D414 + """ method = validate_method(method, tuple(WRITE_IMAGE_METHODS)) diff --git a/colour/io/luts/lut.py b/colour/io/luts/lut.py index 35a9b6329..68ddea748 100644 --- a/colour/io/luts/lut.py +++ b/colour/io/luts/lut.py @@ -155,7 +155,7 @@ def __init__( self._domain: NDArrayFloat = np.array([]) self.domain = optional(domain, self._domain) self._comments: list = [] - self.comments = cast(list, optional(comments, self._comments)) + self.comments = cast("list", optional(comments, self._comments)) @property def table(self) -> NDArrayFloat: @@ -327,7 +327,7 @@ def __str__(self) -> str: } ) - return multiline_str(self, cast(List[dict], attributes)) + return multiline_str(self, cast("List[dict]", attributes)) def __repr__(self) -> str: """ @@ -2195,12 +2195,10 @@ def LUT_to_LUT( LUT.name = name else: size = kwargs.get("size", 33 if cls is LUT3D else 10) - if "size" in kwargs: - del kwargs["size"] + kwargs.pop("size", None) channel_weights = as_float_array(kwargs.get("channel_weights", full(3, 1 / 3))) - if "channel_weights" in kwargs: - del kwargs["channel_weights"] + kwargs.pop("channel_weights", None) if isinstance(LUT, LUT1D): if cls is LUT3x1D: diff --git a/colour/io/luts/operator.py b/colour/io/luts/operator.py index 2f2e31494..49cddbeaf 100644 --- a/colour/io/luts/operator.py +++ b/colour/io/luts/operator.py @@ -403,7 +403,7 @@ def __repr__(self) -> str: [ f"{representation[:-1]},", f"{indentation}" - f'{repr(self._offset).replace("array(", "").replace(")", "")},', + f"{repr(self._offset).replace('array(', '').replace(')', '')},", f"{indentation}name='{self._name}'{comments})", ] ) diff --git a/colour/io/luts/sequence.py b/colour/io/luts/sequence.py index c980559da..81e65b9d8 100644 --- a/colour/io/luts/sequence.py +++ b/colour/io/luts/sequence.py @@ -141,8 +141,7 @@ def sequence(self, value: Sequence[ProtocolLUTSequenceItem]) -> None: for item in value: attest( isinstance(item, ProtocolLUTSequenceItem), - '"value" items must implement the "ProtocolLUTSequenceItem" ' - "protocol!", + '"value" items must implement the "ProtocolLUTSequenceItem" protocol!', ) self._sequence = list(value) @@ -179,8 +178,7 @@ def __setitem__(self, index: int | slice, value: Any) -> None: for item in value if is_iterable(value) else [value]: attest( isinstance(item, ProtocolLUTSequenceItem), - '"value" items must implement the "ProtocolLUTSequenceItem" ' - "protocol!", + '"value" items must implement the "ProtocolLUTSequenceItem" protocol!', ) self._sequence[index] = value diff --git a/colour/io/luts/tests/test__init__.py b/colour/io/luts/tests/test__init__.py index ad85bfd91..5b11e4330 100644 --- a/colour/io/luts/tests/test__init__.py +++ b/colour/io/luts/tests/test__init__.py @@ -39,7 +39,7 @@ def test_read_LUT(self) -> None: """Test :func:`colour.io.luts.__init__.read_LUT` definition.""" LUT_1 = cast( - LUT1D, read_LUT(os.path.join(ROOT_LUTS, "sony_spi1d", "eotf_sRGB_1D.spi1d")) + "LUT1D", read_LUT(os.path.join(ROOT_LUTS, "sony_spi1d", "eotf_sRGB_1D.spi1d")) ) np.testing.assert_allclose( @@ -76,7 +76,7 @@ def test_read_LUT(self) -> None: ] LUT_2 = cast( - LUTSequence, + "LUTSequence", read_LUT(os.path.join(ROOT_LUTS, "resolve_cube", "LogC_Video.cube")), ) np.testing.assert_allclose( diff --git a/colour/io/luts/tests/test_cinespace_csp.py b/colour/io/luts/tests/test_cinespace_csp.py index e543a60ee..fa0fcfa84 100644 --- a/colour/io/luts/tests/test_cinespace_csp.py +++ b/colour/io/luts/tests/test_cinespace_csp.py @@ -50,7 +50,7 @@ def test_read_LUT_Cinespace(self) -> None: """ LUT_1 = cast( - LUT3x1D, + "LUT3x1D", read_LUT_Cinespace(os.path.join(ROOT_LUTS, "ACES_Proxy_10_to_ACES.csp")), ) @@ -100,26 +100,26 @@ def test_read_LUT_Cinespace(self) -> None: assert LUT_1.size == 32 assert LUT_1.comments == [] - LUT_2 = cast(LUT3x1D, read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Demo.csp"))) + LUT_2 = cast("LUT3x1D", read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Demo.csp"))) assert LUT_2.comments == ["Comments are ignored by most parsers"] np.testing.assert_array_equal(LUT_2.domain, np.array([[0, 0, 0], [1, 2, 3]])) LUT_3 = cast( - LUT3D, + "LUT3D", read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Three_Dimensional_Table.csp")), ) assert LUT_3.dimensions == 3 assert LUT_3.size == 2 LUT_4 = cast( - LUTSequence, + "LUTSequence", read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Explicit_Domain.csp")), ) assert LUT_4[0].is_domain_explicit() is True assert LUT_4[1].table.shape == (2, 3, 4, 3) LUT_5 = cast( - LUTSequence, + "LUTSequence", read_LUT_Cinespace( os.path.join(ROOT_LUTS, "Uncommon_3x1D_With_Pre_Lut.csp") ), @@ -163,19 +163,19 @@ def test_write_LUT_Cinespace(self) -> None: assert LUT_1_r == LUT_1_t assert LUT_1_r == LUT_1_t - LUT_2_r = cast(LUT3x1D, read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Demo.csp"))) + LUT_2_r = cast("LUT3x1D", read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Demo.csp"))) write_LUT_Cinespace( LUT_2_r, os.path.join(self._temporary_directory, "Demo.csp") ) LUT_2_t = cast( - LUT3x1D, + "LUT3x1D", read_LUT_Cinespace(os.path.join(self._temporary_directory, "Demo.csp")), ) assert LUT_2_r == LUT_2_t assert LUT_2_r.comments == LUT_2_t.comments LUT_3_r = cast( - LUT3D, + "LUT3D", read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Three_Dimensional_Table.csp")), ) write_LUT_Cinespace( @@ -183,7 +183,7 @@ def test_write_LUT_Cinespace(self) -> None: os.path.join(self._temporary_directory, "Three_Dimensional_Table.csp"), ) LUT_3_t = cast( - LUT3D, + "LUT3D", read_LUT_Cinespace( os.path.join(self._temporary_directory, "Three_Dimensional_Table.csp") ), @@ -203,7 +203,7 @@ def test_write_LUT_Cinespace(self) -> None: os.path.join(self._temporary_directory, "Ragged_Domain.csp"), ) LUT_4_r = cast( - LUT3x1D, read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Ragged_Domain.csp")) + "LUT3x1D", read_LUT_Cinespace(os.path.join(ROOT_LUTS, "Ragged_Domain.csp")) ) np.testing.assert_allclose( LUT_4_t.domain, LUT_4_r.domain, atol=TOLERANCE_ABSOLUTE_TESTS @@ -211,7 +211,7 @@ def test_write_LUT_Cinespace(self) -> None: np.testing.assert_allclose(LUT_4_t.table, LUT_4_r.table, atol=5e-5) LUT_5_r = cast( - LUTSequence, + "LUTSequence", read_LUT_Cinespace( os.path.join(ROOT_LUTS, "Three_Dimensional_Table_With_Shaper.csp") ), @@ -227,13 +227,13 @@ def test_write_LUT_Cinespace(self) -> None: ), ) LUT_5_r = cast( - LUTSequence, + "LUTSequence", read_LUT_Cinespace( os.path.join(ROOT_LUTS, "Three_Dimensional_Table_With_Shaper.csp") ), ) LUT_5_t = cast( - LUTSequence, + "LUTSequence", read_LUT_Cinespace( os.path.join( self._temporary_directory, @@ -244,7 +244,7 @@ def test_write_LUT_Cinespace(self) -> None: assert LUT_5_r == LUT_5_t LUT_6_r = cast( - LUTSequence, + "LUTSequence", read_LUT_Cinespace( os.path.join(ROOT_LUTS, "Three_Dimensional_Table_With_Shaper.csp") ), @@ -260,13 +260,13 @@ def test_write_LUT_Cinespace(self) -> None: ), ) LUT_6_r = cast( - LUTSequence, + "LUTSequence", read_LUT_Cinespace( os.path.join(ROOT_LUTS, "Three_Dimensional_Table_With_Shaper.csp") ), ) LUT_6_t = cast( - LUTSequence, + "LUTSequence", read_LUT_Cinespace( os.path.join( self._temporary_directory, @@ -277,15 +277,15 @@ def test_write_LUT_Cinespace(self) -> None: assert LUT_6_r == LUT_6_t LUT_7_r = cast( - LUT3x1D, + "LUT3x1D", read_LUT_Cinespace(os.path.join(ROOT_LUTS, "ACES_Proxy_10_to_ACES.csp")), ) write_LUT_Cinespace( - cast(LUT1D, LUT_7_r.convert(LUT1D, force_conversion=True)), + cast("LUT1D", LUT_7_r.convert(LUT1D, force_conversion=True)), os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.csp"), ) LUT_7_t = cast( - LUT3x1D, + "LUT3x1D", read_LUT_Cinespace( os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.csp") ), diff --git a/colour/io/luts/tests/test_iridas_cube.py b/colour/io/luts/tests/test_iridas_cube.py index ec050c571..be8df222b 100644 --- a/colour/io/luts/tests/test_iridas_cube.py +++ b/colour/io/luts/tests/test_iridas_cube.py @@ -167,7 +167,7 @@ def test_write_LUT_IridasCube(self) -> None: os.path.join(ROOT_LUTS, "ACES_Proxy_10_to_ACES.cube") ) write_LUT_IridasCube( - cast(LUT1D, LUT_4_r.convert(LUT1D, force_conversion=True)), + cast("LUT1D", LUT_4_r.convert(LUT1D, force_conversion=True)), os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.cube"), ) LUT_4_t = read_LUT_IridasCube( diff --git a/colour/io/luts/tests/test_resolve_cube.py b/colour/io/luts/tests/test_resolve_cube.py index 436c2ffd4..56ec3e9fa 100644 --- a/colour/io/luts/tests/test_resolve_cube.py +++ b/colour/io/luts/tests/test_resolve_cube.py @@ -49,7 +49,7 @@ def test_read_LUT_ResolveCube(self) -> None: """ LUT_1 = cast( - LUT3x1D, + "LUT3x1D", read_LUT_ResolveCube(os.path.join(ROOT_LUTS, "ACES_Proxy_10_to_ACES.cube")), ) @@ -100,13 +100,13 @@ def test_read_LUT_ResolveCube(self) -> None: assert LUT_1.comments == [] LUT_2 = cast( - LUT3x1D, read_LUT_ResolveCube(os.path.join(ROOT_LUTS, "Demo.cube")) + "LUT3x1D", read_LUT_ResolveCube(os.path.join(ROOT_LUTS, "Demo.cube")) ) assert LUT_2.comments == ["Comments can't go anywhere"] np.testing.assert_array_equal(LUT_2.domain, np.array([[0, 0, 0], [3, 3, 3]])) LUT_3 = cast( - LUT3D, + "LUT3D", read_LUT_ResolveCube( os.path.join(ROOT_LUTS, "Three_Dimensional_Table.cube") ), @@ -115,7 +115,7 @@ def test_read_LUT_ResolveCube(self) -> None: assert LUT_3.size == 2 LUT_4 = cast( - LUTSequence, + "LUTSequence", read_LUT_ResolveCube(os.path.join(ROOT_LUTS, "LogC_Video.cube")), ) np.testing.assert_allclose( @@ -183,7 +183,7 @@ def test_write_LUT_ResolveCube(self) -> None: assert LUT_1_r == LUT_1_t LUT_2_r = cast( - LUT3x1D, read_LUT_ResolveCube(os.path.join(ROOT_LUTS, "Demo.cube")) + "LUT3x1D", read_LUT_ResolveCube(os.path.join(ROOT_LUTS, "Demo.cube")) ) write_LUT_ResolveCube( @@ -191,7 +191,7 @@ def test_write_LUT_ResolveCube(self) -> None: ) LUT_2_t = cast( - LUT3x1D, + "LUT3x1D", read_LUT_ResolveCube(os.path.join(self._temporary_directory, "Demo.cube")), ) @@ -199,7 +199,7 @@ def test_write_LUT_ResolveCube(self) -> None: assert LUT_2_r.comments == LUT_2_t.comments LUT_3_r = cast( - LUT3D, + "LUT3D", read_LUT_ResolveCube( os.path.join(ROOT_LUTS, "Three_Dimensional_Table.cube") ), @@ -211,7 +211,7 @@ def test_write_LUT_ResolveCube(self) -> None: ) LUT_3_t = cast( - LUT3D, + "LUT3D", read_LUT_ResolveCube( os.path.join(self._temporary_directory, "Three_Dimensional_Table.cube") ), @@ -219,7 +219,7 @@ def test_write_LUT_ResolveCube(self) -> None: assert LUT_3_r == LUT_3_t LUT_4_r = cast( - LUTSequence, + "LUTSequence", read_LUT_ResolveCube( os.path.join(ROOT_LUTS, "Three_Dimensional_Table_With_Shaper.cube") ), @@ -238,7 +238,7 @@ def test_write_LUT_ResolveCube(self) -> None: ) LUT_4_t = cast( - LUTSequence, + "LUTSequence", read_LUT_ResolveCube( os.path.join( self._temporary_directory, @@ -248,7 +248,7 @@ def test_write_LUT_ResolveCube(self) -> None: ) LUT_4_r = cast( - LUTSequence, + "LUTSequence", read_LUT_ResolveCube( os.path.join(ROOT_LUTS, "Three_Dimensional_Table_With_Shaper.cube") ), @@ -257,17 +257,17 @@ def test_write_LUT_ResolveCube(self) -> None: assert LUT_4_r == LUT_4_t LUT_5_r = cast( - LUT3x1D, + "LUT3x1D", read_LUT_ResolveCube(os.path.join(ROOT_LUTS, "ACES_Proxy_10_to_ACES.cube")), ) write_LUT_ResolveCube( - cast(LUT1D, LUT_5_r.convert(LUT1D, force_conversion=True)), + cast("LUT1D", LUT_5_r.convert(LUT1D, force_conversion=True)), os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.cube"), ) LUT_5_t = cast( - LUT3x1D, + "LUT3x1D", read_LUT_ResolveCube( os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.cube") ), diff --git a/colour/io/tabular.py b/colour/io/tabular.py index a6f789f62..2b2d30907 100644 --- a/colour/io/tabular.py +++ b/colour/io/tabular.py @@ -138,7 +138,7 @@ def read_spectral_data_from_csv_file( transpose = settings.get("transpose") if transpose: - delimiter = cast(str, settings.get("delimiter", ",")) + delimiter = cast("str", settings.get("delimiter", ",")) with open(path) as csv_file: content = zip(*csv.reader(csv_file, delimiter=delimiter), strict=True) diff --git a/colour/io/tests/test_fichet2021.py b/colour/io/tests/test_fichet2021.py index 3752eb722..9c611880f 100644 --- a/colour/io/tests/test_fichet2021.py +++ b/colour/io/tests/test_fichet2021.py @@ -190,7 +190,7 @@ def test_components_to_sRGB_Fichet2021(self) -> None: RGB, attributes = components_to_sRGB_Fichet2021(components, specification) np.testing.assert_allclose( - cast(NDArrayFloat, RGB), + cast("NDArrayFloat", RGB), np.array([[[0.17998291, 0.18000802, 0.18000908]]]), atol=TOLERANCE_ABSOLUTE_TESTS, ) @@ -240,7 +240,7 @@ def test_components_to_sRGB_Fichet2021(self) -> None: RGB, attributes = components_to_sRGB_Fichet2021(components, specification) np.testing.assert_allclose( - cast(NDArrayFloat, RGB), + cast("NDArrayFloat", RGB), np.array( [ [ diff --git a/colour/io/tests/test_tm2714.py b/colour/io/tests/test_tm2714.py index 9e102f42a..7ee2328c8 100644 --- a/colour/io/tests/test_tm2714.py +++ b/colour/io/tests/test_tm2714.py @@ -586,7 +586,7 @@ def test_read(self, sd: SpectralDistribution | None = None) -> None: """ sd = cast( - SpectralDistribution_IESTM2714, + "SpectralDistribution_IESTM2714", optional( sd, SpectralDistribution_IESTM2714( diff --git a/colour/io/tm2714.py b/colour/io/tm2714.py index 61720aa4f..61e0ab315 100644 --- a/colour/io/tm2714.py +++ b/colour/io/tm2714.py @@ -1676,8 +1676,7 @@ def read(self) -> SpectralDistribution_IESTM2714: namespace = match.group(1) else: error = ( - 'The "IES TM-27-14" spectral distribution namespace ' - "was not found!" + 'The "IES TM-27-14" spectral distribution namespace was not found!' ) raise ValueError(error) diff --git a/colour/io/uprtek_sekonic.py b/colour/io/uprtek_sekonic.py index 88c9abfed..f362cc631 100644 --- a/colour/io/uprtek_sekonic.py +++ b/colour/io/uprtek_sekonic.py @@ -276,10 +276,7 @@ def __str__(self) -> str: representation = super().__str__() return representation.replace( - ( - "IES TM-27-14 Spectral Distribution\n" - "==================================" - ), + ("IES TM-27-14 Spectral Distribution\n=================================="), "UPRTek\n======", ) @@ -373,7 +370,7 @@ def read(self) -> SpectralDistribution_UPRTek: [ 7.80000000e+02 4.11766000e-01]] """ - path = cast(str, self.path) + path = cast("str", self.path) def as_array(a: Any) -> list: """ diff --git a/colour/models/cam02_ucs.py b/colour/models/cam02_ucs.py index 115b426bd..3eccfc5ee 100644 --- a/colour/models/cam02_ucs.py +++ b/colour/models/cam02_ucs.py @@ -697,9 +697,9 @@ def XYZ_to_UCS_Luo2006( specification = XYZ_to_CIECAM02(XYZ, **settings) JMh = tstack( [ - cast(NDArrayFloat, specification.J), - cast(NDArrayFloat, specification.M), - cast(NDArrayFloat, specification.h), + cast("NDArrayFloat", specification.J), + cast("NDArrayFloat", specification.M), + cast("NDArrayFloat", specification.h), ] ) diff --git a/colour/models/cam16_ucs.py b/colour/models/cam16_ucs.py index da56a9896..4f60f103a 100644 --- a/colour/models/cam16_ucs.py +++ b/colour/models/cam16_ucs.py @@ -262,9 +262,9 @@ def XYZ_to_UCS_Li2017( specification = XYZ_to_CAM16(XYZ, **settings) JMh = tstack( [ - cast(NDArrayFloat, specification.J), - cast(NDArrayFloat, specification.M), - cast(NDArrayFloat, specification.h), + cast("NDArrayFloat", specification.J), + cast("NDArrayFloat", specification.M), + cast("NDArrayFloat", specification.h), ] ) diff --git a/colour/models/rgb/cylindrical.py b/colour/models/rgb/cylindrical.py index e9959482f..1903dcc73 100644 --- a/colour/models/rgb/cylindrical.py +++ b/colour/models/rgb/cylindrical.py @@ -521,7 +521,7 @@ def HCL_to_RGB(HCL: ArrayLike, gamma: float = 3, Y_0: float = 100) -> NDArrayFlo def _1_2_3(a: ArrayLike) -> NDArrayFloat: """Tail-stack given :math:`a` array as a *bool* dtype.""" - return tstack(cast(ArrayLike, [a, a, a]), dtype=np.bool_) + return tstack(cast("ArrayLike", [a, a, a]), dtype=np.bool_) with sdiv_mode(): RGB = np.select( diff --git a/colour/models/rgb/rgb_colourspace.py b/colour/models/rgb/rgb_colourspace.py index f2aae7528..587c98e11 100644 --- a/colour/models/rgb/rgb_colourspace.py +++ b/colour/models/rgb/rgb_colourspace.py @@ -911,7 +911,7 @@ def chromatically_adapt( colourspace.name = ( f"{colourspace.name} - Chromatically Adapted to " - f"{cast(str, optional(whitepoint_name, whitepoint))!r}" + f"{cast('str', optional(whitepoint_name, whitepoint))!r}" ) return colourspace @@ -1250,7 +1250,7 @@ def matrix_RGB_to_RGB( tuple(RGB_COLOURSPACES), '"{0}" "RGB" colourspace is invalid, it must be one of {1}!', ) - input_colourspace = cast(RGB_Colourspace, RGB_COLOURSPACES[input_colourspace]) + input_colourspace = cast("RGB_Colourspace", RGB_COLOURSPACES[input_colourspace]) if isinstance(output_colourspace, str): output_colourspace = validate_method( @@ -1258,7 +1258,7 @@ def matrix_RGB_to_RGB( tuple(RGB_COLOURSPACES), '"{0}" "RGB" colourspace is invalid, it must be one of {1}!', ) - output_colourspace = cast(RGB_Colourspace, RGB_COLOURSPACES[output_colourspace]) + output_colourspace = cast("RGB_Colourspace", RGB_COLOURSPACES[output_colourspace]) M = input_colourspace.matrix_RGB_to_XYZ @@ -1354,7 +1354,7 @@ def RGB_to_RGB( tuple(RGB_COLOURSPACES), '"{0}" "RGB" colourspace is invalid, it must be one of {1}!', ) - input_colourspace = cast(RGB_Colourspace, RGB_COLOURSPACES[input_colourspace]) + input_colourspace = cast("RGB_Colourspace", RGB_COLOURSPACES[input_colourspace]) if isinstance(output_colourspace, str): output_colourspace = validate_method( @@ -1362,7 +1362,7 @@ def RGB_to_RGB( tuple(RGB_COLOURSPACES), '"{0}" "RGB" colourspace is invalid, it must be one of {1}!', ) - output_colourspace = cast(RGB_Colourspace, RGB_COLOURSPACES[output_colourspace]) + output_colourspace = cast("RGB_Colourspace", RGB_COLOURSPACES[output_colourspace]) RGB = to_domain_1(RGB) diff --git a/colour/models/rgb/transfer_functions/log.py b/colour/models/rgb/transfer_functions/log.py index 991b23514..4c6c13a34 100644 --- a/colour/models/rgb/transfer_functions/log.py +++ b/colour/models/rgb/transfer_functions/log.py @@ -319,7 +319,7 @@ def logarithmic_function_camera( with sdiv_mode(): linear_slope = cast( - float, + "float", optional( linear_slope, ( diff --git a/colour/models/rgb/ycbcr.py b/colour/models/rgb/ycbcr.py index aea232617..06e5a93c8 100644 --- a/colour/models/rgb/ycbcr.py +++ b/colour/models/rgb/ycbcr.py @@ -142,7 +142,7 @@ def round_BT2100(a: ArrayLike) -> NDArrayFloat: array([ 0., 1., 1.]) """ - return cast(NDArrayFloat, np.sign(a) * np.floor(np.abs(a) + 0.5)) + return cast("NDArrayFloat", np.sign(a) * np.floor(np.abs(a) + 0.5)) def ranges_YCbCr(bits: int, is_legal: bool, is_int: bool) -> NDArrayFloat: diff --git a/colour/notation/munsell.py b/colour/notation/munsell.py index 57899bade..d20e9b3b5 100644 --- a/colour/notation/munsell.py +++ b/colour/notation/munsell.py @@ -352,9 +352,9 @@ def _munsell_value_ASTMD1535_interpolator() -> Extrapolator: return extrapolator -def _munsell_maximum_chromas_from_renotation() -> ( - Tuple[Tuple[Tuple[float, float], float], ...] -): +def _munsell_maximum_chromas_from_renotation() -> Tuple[ + Tuple[Tuple[float, float], float], ... +]: """ Return the maximum *Munsell* chromas from *Munsell Renotation System* data and caches them if not existing. @@ -385,7 +385,7 @@ def _munsell_maximum_chromas_from_renotation() -> ( if index in chromas: chroma = max([chromas[index], chroma]) - chromas[index] = cast(float, chroma) + chromas[index] = cast("float", chroma) maximum_chromas_from_renotation = tuple(chromas.items()) @@ -1215,7 +1215,7 @@ def _xyY_to_munsell_specification(xyY: ArrayLike) -> NDArrayFloat: % 360 ) hue_angle_new = cast( - float, (hue_angle_current + hue_angle_difference_new) % 360 + "float", (hue_angle_current + hue_angle_difference_new) % 360 ) hue_new, code_new = hue_angle_to_hue(hue_angle_new) @@ -1658,8 +1658,7 @@ def munsell_specification_to_munsell_colour( hue = round(hue, hue_decimals) attest( 0 <= hue <= 10, - f'"{specification!r}" specification hue must be normalised to ' - f"domain [0, 10]!", + f'"{specification!r}" specification hue must be normalised to domain [0, 10]!', ) value = round(value, value_decimals) @@ -1955,7 +1954,7 @@ def hue_angle_to_hue(hue_angle: float) -> NDArrayFloat: if hue == 0: hue = 10 - return tstack(cast(ArrayLike, [hue, code])) + return tstack(cast("ArrayLike", [hue, code])) def hue_to_ASTM_hue(hue_and_code: ArrayLike) -> float: @@ -2055,8 +2054,7 @@ def interpolation_method_from_renotation_ovoid( attest( abs(2 * (chroma / 2 - round(chroma / 2))) <= THRESHOLD_INTEGER, - f'"{specification}" specification chroma must be an int and ' - f"multiple of 2!", + f'"{specification}" specification chroma must be an int and multiple of 2!', ) chroma = 2 * round(chroma / 2) @@ -2318,8 +2316,7 @@ def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArrayFloat: attest( 1 <= value <= 9, - f'"{specification}" specification value must be normalised to ' - f"domain [1, 9]!", + f'"{specification}" specification value must be normalised to domain [1, 9]!', ) attest( @@ -2331,8 +2328,7 @@ def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArrayFloat: attest( 2 <= chroma <= 50, - f'"{specification}" specification chroma must be normalised to ' - f"domain [2, 50]!", + f'"{specification}" specification chroma must be normalised to domain [2, 50]!', ) attest( @@ -2398,7 +2394,7 @@ def xy_from_renotation_ovoid(specification: ArrayLike) -> NDArrayFloat: attest( interpolation_method is not None, - f"Interpolation method must be one of: \"{'Linear, Radial'}\"", + f'Interpolation method must be one of: "{"Linear, Radial"}"', ) hue_angle_lower_upper = np.squeeze([hue_angle_lower, hue_angle_upper]) @@ -2484,7 +2480,7 @@ def LCHab_to_munsell_specification(LCHab: ArrayLike) -> NDArrayFloat: value = L / 10 chroma = C / 5 - return tstack(cast(ArrayLike, [hue, value, chroma, code])) + return tstack(cast("ArrayLike", [hue, value, chroma, code])) def maximum_chroma_from_renotation(hue_and_value_and_code: ArrayLike) -> float: @@ -2615,8 +2611,7 @@ def munsell_specification_to_xy(specification: ArrayLike) -> NDArrayFloat: attest( 0 <= value <= 10, - f'"{specification}" specification value must be normalised to ' - f"domain [0, 10]!", + f'"{specification}" specification value must be normalised to domain [0, 10]!', ) attest( diff --git a/colour/plotting/colorimetry.py b/colour/plotting/colorimetry.py index 774e39c5c..22c020d0a 100644 --- a/colour/plotting/colorimetry.py +++ b/colour/plotting/colorimetry.py @@ -186,7 +186,7 @@ def plot_single_sd( _figure, axes = artist(**kwargs) - cmfs = cast(MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values())) + cmfs = cast("MultiSpectralDistributions", first_item(filter_cmfs(cmfs).values())) sd = sd.copy() sd.interpolator = LinearInterpolator @@ -388,11 +388,11 @@ def plot_multi_sds( plot_settings = plot_settings_collection[i] cmfs = cast( - MultiSpectralDistributions, + "MultiSpectralDistributions", first_item(filter_cmfs(plot_settings.pop("cmfs")).values()), ) illuminant = cast( - SpectralDistribution, + "SpectralDistribution", first_item(filter_illuminants(plot_settings.pop("illuminant")).values()), ) normalise_sd_colours = plot_settings.pop("normalise_sd_colours") @@ -475,7 +475,7 @@ def plot_single_cmfs( :alt: plot_single_cmfs """ - cmfs = cast(MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values())) + cmfs = cast("MultiSpectralDistributions", first_item(filter_cmfs(cmfs).values())) settings: Dict[str, Any] = { "title": f"{cmfs.display_name} - Colour Matching Functions" @@ -527,7 +527,7 @@ def plot_multi_cmfs( :alt: plot_multi_cmfs """ - cmfs = cast(List[MultiSpectralDistributions], list(filter_cmfs(cmfs).values())) # pyright: ignore + cmfs = cast("List[MultiSpectralDistributions]", list(filter_cmfs(cmfs).values())) # pyright: ignore _figure, axes = artist(**kwargs) @@ -629,12 +629,12 @@ def plot_single_illuminant_sd( :alt: plot_single_illuminant_sd """ - cmfs = cast(MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values())) + cmfs = cast("MultiSpectralDistributions", first_item(filter_cmfs(cmfs).values())) title = f"Illuminant {illuminant} - {cmfs.display_name}" illuminant = cast( - SpectralDistribution, + "SpectralDistribution", first_item(filter_illuminants(illuminant).values()), ) @@ -693,7 +693,7 @@ def plot_multi_illuminant_sds( kwargs["plot_kwargs"][i]["illuminant"] = SD_E illuminants = cast( - List[SpectralDistribution], + "List[SpectralDistribution]", list(filter_illuminants(illuminants).values()), ) # pyright: ignore @@ -763,7 +763,7 @@ def plot_visible_spectrum( :alt: plot_visible_spectrum """ - cmfs = cast(MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values())) + cmfs = cast("MultiSpectralDistributions", first_item(filter_cmfs(cmfs).values())) bounding_box = (min(cmfs.wavelengths), max(cmfs.wavelengths), 0, 1) @@ -1034,7 +1034,7 @@ def plot_blackbody_spectral_radiance( figure.subplots_adjust(hspace=CONSTANTS_COLOUR_STYLE.geometry.short / 2) - cmfs = cast(MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values())) + cmfs = cast("MultiSpectralDistributions", first_item(filter_cmfs(cmfs).values())) sd = sd_blackbody(temperature, cmfs.shape) @@ -1127,7 +1127,7 @@ def plot_blackbody_colours( _figure, axes = artist(**kwargs) - cmfs = cast(MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values())) + cmfs = cast("MultiSpectralDistributions", first_item(filter_cmfs(cmfs).values())) RGB = [] temperatures = [] diff --git a/colour/plotting/common.py b/colour/plotting/common.py index 9af892e73..c1bd48a8b 100644 --- a/colour/plotting/common.py +++ b/colour/plotting/common.py @@ -223,7 +223,7 @@ # affecting *Matplotplib* ones. for _scaling, _value in CONSTANTS_COLOUR_STYLE.font.scaling.items(): matplotlib.font_manager.font_scalings[ - f'{_scaling.replace("_", "-")}-colour-science' + f"{_scaling.replace('_', '-')}-colour-science" ] = _value del _scaling, _value @@ -539,13 +539,13 @@ def artist(**kwargs: KwargsArtist | Any) -> Tuple[Figure, Axes]: return figure, figure.gca() - axes = cast(Axes, axes) + axes = cast("Axes", axes) figure = axes.figure if isinstance(figure, SubFigure): figure = figure.get_figure() - return cast(Figure, figure), axes + return cast("Figure", figure), axes class KwargsCamera(TypedDict): @@ -590,8 +590,8 @@ def camera(**kwargs: KwargsCamera | Any) -> Tuple[Figure, Axes3D]: Current figure and axes. """ - figure = cast(Figure, kwargs.get("figure", plt.gcf())) - axes = cast(Axes3D, kwargs.get("axes", plt.gca())) + figure = cast("Figure", kwargs.get("figure", plt.gcf())) + axes = cast("Axes3D", kwargs.get("axes", plt.gca())) settings = Structure(camera_aspect="equal", elevation=None, azimuth=None) settings.update(kwargs) @@ -698,8 +698,8 @@ def render( Current figure and axes. """ - figure = cast(Figure, kwargs.get("figure", plt.gcf())) - axes = cast(Axes, kwargs.get("axes", plt.gca())) + figure = cast("Figure", kwargs.get("figure", plt.gcf())) + axes = cast("Axes", kwargs.get("axes", plt.gca())) kwargs = handle_arguments_deprecation( { @@ -1312,12 +1312,12 @@ def plot_multi_colour_swatches( if not isinstance(first_item(colour_swatches), ColourSwatch): for _i, colour_swatch in enumerate( np.reshape( - as_float_array(cast(ArrayLike, colour_swatches))[..., :3], (-1, 3) + as_float_array(cast("ArrayLike", colour_swatches))[..., :3], (-1, 3) ) ): colour_swatches_converted.append(ColourSwatch(colour_swatch)) else: - colour_swatches_converted = cast(List[ColourSwatch], colour_swatches) + colour_swatches_converted = cast("List[ColourSwatch]", colour_swatches) colour_swatches = colour_swatches_converted diff --git a/colour/plotting/corresponding.py b/colour/plotting/corresponding.py index 88f3eed3d..b2e7a6296 100644 --- a/colour/plotting/corresponding.py +++ b/colour/plotting/corresponding.py @@ -112,7 +112,7 @@ def plot_corresponding_chromaticities_prediction( name = ( f"Experiment {experiment}" if is_numeric(experiment) - else cast(CorrespondingColourDataset, experiment).name + else cast("CorrespondingColourDataset", experiment).name ) title = ( f"Corresponding Chromaticities Prediction - {model} - {name} - " diff --git a/colour/plotting/diagrams.py b/colour/plotting/diagrams.py index 8f83058e8..0bdace692 100644 --- a/colour/plotting/diagrams.py +++ b/colour/plotting/diagrams.py @@ -262,7 +262,7 @@ def lines_spectral_locus( ('colour', ' None: samples = np.linspace(0, 1, 10) _figure, axes = label_rectangles( - cast(List[float], samples.tolist()), + cast("List[float]", samples.tolist()), axes.bar(samples, 1), figure=figure, axes=axes, @@ -318,7 +318,7 @@ def test_uniform_axes3d(self) -> None: """Test :func:`colour.plotting.common.uniform_axes3d` definition.""" figure, _axes = artist() - axes = cast(Axes3D, figure.add_subplot(111, projection="3d")) + axes = cast("Axes3D", figure.add_subplot(111, projection="3d")) uniform_axes3d(axes=axes) diff --git a/colour/plotting/tm3018/report.py b/colour/plotting/tm3018/report.py index 4ac35813f..f9834209c 100644 --- a/colour/plotting/tm3018/report.py +++ b/colour/plotting/tm3018/report.py @@ -299,7 +299,7 @@ def plot_single_sd_colour_rendition_report_full( Plot_Single_SD_Colour_Rendition_Report_Full.png :align: center :alt: plot_single_sd_colour_rendition_report_full - """ # noqa: D405, D407, D410, D411 + """ report_box_padding = optional(report_box_padding, CONSTANT_REPORT_PADDING_FULL) diff --git a/colour/plotting/volume.py b/colour/plotting/volume.py index e0a9fb006..cb3bfc0ac 100644 --- a/colour/plotting/volume.py +++ b/colour/plotting/volume.py @@ -185,7 +185,7 @@ def nadir_grid( """ limits = as_float_array(optional(limits, np.array([[-1, 1], [-1, 1]]))) - labels = cast(Sequence, optional(labels, ("x", "y"))) + labels = cast("Sequence", optional(labels, ("x", "y"))) extent = np.max(np.abs(limits[..., 1] - limits[..., 0])) @@ -503,7 +503,7 @@ def plot_RGB_colourspaces_gamuts( ).get("model", model) colourspaces = cast( - List[RGB_Colourspace], + "List[RGB_Colourspace]", list(filter_RGB_colourspaces(colourspaces).values()), ) # pyright: ignore @@ -528,11 +528,11 @@ def plot_RGB_colourspaces_gamuts( settings.update(kwargs) figure = plt.figure() - axes = cast(Axes3D, figure.add_subplot(111, projection="3d")) + axes = cast("Axes3D", figure.add_subplot(111, projection="3d")) points = zeros((4, 3)) if show_spectral_locus: - cmfs = cast(MultiSpectralDistributions, first_item(filter_cmfs(cmfs).values())) + cmfs = cast("MultiSpectralDistributions", first_item(filter_cmfs(cmfs).values())) XYZ = cmfs.values points = colourspace_model_axis_reorder( @@ -645,7 +645,7 @@ def plot_RGB_colourspaces_gamuts( settings.update({"axes": axes, "axes_visible": False, "camera_aspect": "equal"}) settings.update(kwargs) - return cast(Tuple[Figure, Axes3D], render(**settings)) + return cast("Tuple[Figure, Axes3D]", render(**settings)) @override_style() @@ -740,10 +740,10 @@ def plot_RGB_scatter( RGB = np.reshape(as_float_array(RGB)[..., :3], (-1, 3)) colourspace = cast( - RGB_Colourspace, + "RGB_Colourspace", first_item(filter_RGB_colourspaces(colourspace).values()), ) - colourspaces = cast(List[str], optional(colourspaces, [colourspace.name])) + colourspaces = cast("List[str]", optional(colourspaces, [colourspace.name])) convert_kwargs = optional(convert_kwargs, {}) @@ -793,4 +793,4 @@ def plot_RGB_scatter( settings.update({"axes": axes, "show": True}) settings.update(kwargs) - return cast(Tuple[Figure, Axes3D], render(**settings)) + return cast("Tuple[Figure, Axes3D]", render(**settings)) diff --git a/colour/quality/cfi2017.py b/colour/quality/cfi2017.py index f9d271cea..574c1b113 100644 --- a/colour/quality/cfi2017.py +++ b/colour/quality/cfi2017.py @@ -247,7 +247,7 @@ def colour_fidelity_index_CIE2017( ) R_s = delta_E_to_R_f(delta_E_s) - R_f = cast(float, delta_E_to_R_f(np.average(delta_E_s))) + R_f = cast("float", delta_E_to_R_f(np.average(delta_E_s))) if additional_data: return ColourRendering_Specification_CIE2017( @@ -516,9 +516,9 @@ def tcs_colorimetry_data( JMh = tstack( [ - cast(NDArrayFloat, specification.J), - cast(NDArrayFloat, specification.M), - cast(NDArrayFloat, specification.h), + cast("NDArrayFloat", specification.J), + cast("NDArrayFloat", specification.M), + cast("NDArrayFloat", specification.h), ] ) Jpapbp = JMh_CIECAM02_to_CAM02UCS(JMh) diff --git a/colour/quality/cqs.py b/colour/quality/cqs.py index 0f514dabd..fba0f3865 100644 --- a/colour/quality/cqs.py +++ b/colour/quality/cqs.py @@ -305,7 +305,7 @@ def colour_quality_scale( Q_p = Q_d = None else: p_delta_C = cast( - float, + "float", np.average([max(0, sample_data.D_C_ab) for sample_data in Q_as.values()]), ) Q_p = 100 - 3.6 * (D_Ep_RMS - p_delta_C) @@ -560,11 +560,11 @@ def colour_quality_scales( Q_as = {} for i in range(len(test_data)): - D_C_ab = cast(float, test_data[i].C - reference_data[i].C) + D_C_ab = cast("float", test_data[i].C - reference_data[i].C) D_E_ab = cast( - float, euclidean_distance(test_data[i].Lab, reference_data[i].Lab) + "float", euclidean_distance(test_data[i].Lab, reference_data[i].Lab) ) - D_Ep_ab = cast(float, np.sqrt(D_E_ab**2 - D_C_ab**2) if D_C_ab > 0 else D_E_ab) + D_Ep_ab = cast("float", np.sqrt(D_E_ab**2 - D_C_ab**2) if D_C_ab > 0 else D_E_ab) Q_a = scale_conversion(D_Ep_ab, CCT_f, scaling_f) Q_as[i + 1] = DataColourQualityScale_VS( diff --git a/colour/quality/cri.py b/colour/quality/cri.py index 985b81d31..68c95e8a9 100644 --- a/colour/quality/cri.py +++ b/colour/quality/cri.py @@ -224,7 +224,7 @@ def colour_rendering_index( ) Q_a = cast( - float, + "float", np.average([v.Q_a for k, v in Q_as.items() if k in (1, 2, 3, 4, 5, 6, 7, 8)]), ) @@ -357,7 +357,7 @@ def colour_rendering_indexes( 100 - 4.6 * cast( - float, + "float", euclidean_distance(reference_data[i].UVW, test_data[i].UVW), ), ) diff --git a/colour/recovery/jiang2013.py b/colour/recovery/jiang2013.py index 951877ba3..085888062 100644 --- a/colour/recovery/jiang2013.py +++ b/colour/recovery/jiang2013.py @@ -140,7 +140,7 @@ def normalised_sensitivity( ) -> NDArrayFloat: """Return a normalised camera *RGB* sensitivity.""" - sensitivity = cast(SpectralDistribution, msds.signals[channel].copy()) + sensitivity = cast("SpectralDistribution", msds.signals[channel].copy()) return sensitivity.normalise().values diff --git a/colour/recovery/otsu2018.py b/colour/recovery/otsu2018.py index 71118f54e..4d51aef27 100644 --- a/colour/recovery/otsu2018.py +++ b/colour/recovery/otsu2018.py @@ -413,9 +413,9 @@ def write(self, path: str | PathLike) -> None: self._shape.interval, ] ), - basis_functions=cast(NDArrayFloat, self._basis_functions), - means=cast(NDArrayFloat, self._means), - selector_array=cast(NDArrayFloat, self._selector_array), + basis_functions=cast("NDArrayFloat", self._basis_functions), + means=cast("NDArrayFloat", self._means), + selector_array=cast("NDArrayFloat", self._selector_array), ) else: error = 'The "shape" is undefined!' @@ -857,14 +857,14 @@ def partition(self, axis: PartitionAxis) -> Tuple[Data_Otsu2018, Data_Otsu2018]: ): mask = self._xy[:, axis.direction] <= axis.origin - lesser._reflectances = self._reflectances[mask, :] # noqa: SLF001 - greater._reflectances = self._reflectances[~mask, :] # noqa: SLF001 + lesser._reflectances = self._reflectances[mask, :] + greater._reflectances = self._reflectances[~mask, :] - lesser._XYZ = self._XYZ[mask, :] # noqa: SLF001 - greater._XYZ = self._XYZ[~mask, :] # noqa: SLF001 + lesser._XYZ = self._XYZ[mask, :] + greater._XYZ = self._XYZ[~mask, :] - lesser._xy = self._xy[mask, :] # noqa: SLF001 - greater._xy = self._xy[~mask, :] # noqa: SLF001 + lesser._xy = self._xy[mask, :] + greater._xy = self._xy[~mask, :] return lesser, greater @@ -887,7 +887,7 @@ def PCA(self) -> None: self._mean = np.mean(self._reflectances, axis=0) self._XYZ_mu = ( - msds_to_XYZ_integration(cast(NDArrayFloat, self._mean), **settings) + msds_to_XYZ_integration(cast("NDArrayFloat", self._mean), **settings) / 100 ) @@ -980,7 +980,7 @@ def reconstruction_error(self) -> float: XYZ = self._XYZ[i, :] recovered_sd = self.reconstruct(XYZ) reconstruction_error += cast( - float, np.sum((sd - recovered_sd.values) ** 2) + "float", np.sum((sd - recovered_sd.values) ** 2) ) self._reconstruction_error = reconstruction_error @@ -1477,7 +1477,7 @@ def optimise( default_cluster_size = len(self.data) / iterations // 2 minimum_cluster_size = max( - cast(int, optional(minimum_cluster_size, default_cluster_size)), 3 + cast("int", optional(minimum_cluster_size, default_cluster_size)), 3 ) initial_branch_error = self.branch_reconstruction_error() @@ -1601,7 +1601,7 @@ def add_rows(node: Node_Otsu2018, data: dict | None = None) -> dict | None: return data - data = cast(dict, add_rows(self)) + data = cast("dict", add_rows(self)) rows = data["rows"] for i, row in enumerate(rows): diff --git a/colour/recovery/tests/test_jiang2013.py b/colour/recovery/tests/test_jiang2013.py index 53ee4171c..a21f1953a 100644 --- a/colour/recovery/tests/test_jiang2013.py +++ b/colour/recovery/tests/test_jiang2013.py @@ -204,7 +204,7 @@ def setup_fixture_jiang_2013(self) -> None: reflectances = list(SDS_COLOURCHECKERS["BabelColor Average"].values()) self._reflectances = sds_and_msds_to_msds(reflectances) self._RGB = msds_to_XYZ( - cast(SpectralDistribution, self._reflectances.copy()).align( + cast("SpectralDistribution", self._reflectances.copy()).align( SPECTRAL_SHAPE_BASIS_FUNCTIONS_DYER2017 ), method="Integration", diff --git a/colour/utilities/array.py b/colour/utilities/array.py index d16a5a3bf..80e22aad1 100644 --- a/colour/utilities/array.py +++ b/colour/utilities/array.py @@ -277,7 +277,7 @@ def __array__( return tstack( cast( - ArrayLike, + "ArrayLike", [value if value is not None else default for value in self.values], ), dtype=dtype, @@ -801,7 +801,7 @@ def as_int_scalar(a: ArrayLike, dtype: Type[DTypeInt] | None = None) -> int: attest(a.ndim == 0, f'"{a}" cannot be converted to "int" scalar!') # TODO: Revisit when Numpy types are well established. - return cast(int, as_int(a, dtype)) + return cast("int", as_int(a, dtype)) def as_float_scalar(a: ArrayLike, dtype: Type[DTypeFloat] | None = None) -> float: @@ -839,7 +839,7 @@ def as_float_scalar(a: ArrayLike, dtype: Type[DTypeFloat] | None = None) -> floa attest(a.ndim == 0, f'"{a}" cannot be converted to "float" scalar!') # TODO: Revisit when Numpy types are well established. - return cast(float, as_float(a, dtype)) + return cast("float", as_float(a, dtype)) def set_default_int_dtype( diff --git a/colour/utilities/network.py b/colour/utilities/network.py index f869725f2..9705f34d2 100644 --- a/colour/utilities/network.py +++ b/colour/utilities/network.py @@ -136,7 +136,7 @@ class TreeNode: _INSTANCE_ID """ - def __new__(cls, *args: Any, **kwargs: Any) -> Self: # noqa: ARG003 + def __new__(cls, *args: Any, **kwargs: Any) -> Self: """ Return a new instance of the :class:`colour.utilities.Node` class. @@ -150,7 +150,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Self: # noqa: ARG003 instance = super().__new__(cls) - instance._id = TreeNode._INSTANCE_ID # pyright: ignore # noqa: SLF001 + instance._id = TreeNode._INSTANCE_ID # pyright: ignore TreeNode._INSTANCE_ID += 1 return instance @@ -741,8 +741,7 @@ def node(self, value: PortNode | None) -> None: attest( value is None or isinstance(value, PortNode), - f'"node" property: "{value}" is not "None" or ' - f'its type is not "PortNode"!', + f'"node" property: "{value}" is not "None" or its type is not "PortNode"!', ) self._node = value diff --git a/colour/utilities/verbose.py b/colour/utilities/verbose.py index 0ea54485c..7930ca7a0 100644 --- a/colour/utilities/verbose.py +++ b/colour/utilities/verbose.py @@ -207,9 +207,9 @@ def inner(text: str) -> str: """Format and pads inner text for the message box.""" return ( - f'*{" " * padding}' - f'{text}{" " * (width - len(text) - padding * 2 - 2)}' - f'{" " * padding}*' + f"*{' ' * padding}" + f"{text}{' ' * (width - len(text) - padding * 2 - 2)}" + f"{' ' * padding}*" ) print_callable("=" * width) @@ -322,7 +322,7 @@ def warning(*args: Any, **kwargs: Any) -> None: kwargs["category"] = kwargs.get("category", ColourWarning) - warn(*args, **kwargs) # noqa: B028 + warn(*args, **kwargs) def runtime_warning(*args: Any, **kwargs: Any) -> None: @@ -444,7 +444,7 @@ def filter_warnings( continue if isinstance(action, str): - action = cast(LiteralWarning, str(action)) # noqa: PLW2901 + action = cast("LiteralWarning", str(action)) # noqa: PLW2901 else: action = "ignore" if action else "default" # noqa: PLW2901 @@ -1016,7 +1016,7 @@ def multiline_str( List ---- List "c" : John; Doe - """ # noqa: D405, D407, D410, D411 + """ attribute_defaults = { "name": None, @@ -1130,7 +1130,7 @@ def multiline_repr( Data('Foo', 1, ('John', 'Doe')) - """ # noqa: D405, D407, D410, D411 + """ attribute_defaults = {"name": None, "formatter": repr} diff --git a/utilities/export_todo.py b/utilities/export_todo.py index 0f587b659..01bca9233 100755 --- a/utilities/export_todo.py +++ b/utilities/export_todo.py @@ -81,7 +81,7 @@ def extract_todo_items(root_directory: str) -> dict: if in_todo and line.startswith("#"): todo_item.append(line.replace("#", "").strip()) - elif len(todo_item): + elif todo_item: key = filename.replace("../", "") if not todo_items.get(key): todo_items[key] = [] diff --git a/utilities/generate_plots.py b/utilities/generate_plots.py index df0c2f4fb..58eb25be8 100755 --- a/utilities/generate_plots.py +++ b/utilities/generate_plots.py @@ -1147,7 +1147,7 @@ def generate_documentation_plots(output_directory: str) -> None: arguments["filename"] = os.path.join( output_directory, "Tutorial_CIE_1931_Chromaticity_Diagram.png" ) - xy = cast(tuple[float, float], XYZ_to_xy(XYZ)) + xy = cast("tuple[float, float]", XYZ_to_xy(XYZ)) plot_chromaticity_diagram_CIE1931(standalone=False) plt.plot(xy[0], xy[1], "o-", color="white") # Annotating the plot.