From 8b440b956a9c5346999be06b5c311449c5adef31 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Mon, 13 Jan 2025 22:03:40 +1300 Subject: [PATCH 1/3] Use walrus operator for `re.match` usage. --- colour/io/fichet2021.py | 12 ++++-------- colour/io/uprtek_sekonic.py | 5 +++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/colour/io/fichet2021.py b/colour/io/fichet2021.py index 8ac30fc6f..63224d02b 100644 --- a/colour/io/fichet2021.py +++ b/colour/io/fichet2021.py @@ -268,8 +268,7 @@ def spectrum_attribute_to_sd_Fichet2021( parts = spectrum_attribute.split(";") for part in parts: domain, range_ = part.split(":") - match = pattern.match(domain.replace(".", ",")) - if match is not None: + if (match := pattern.match(domain.replace(".", ","))) is not None: multiplier, units = match.group(3, 4) wavelength = match_groups_to_nm(match.group(1), multiplier, units) data[wavelength] = float(range_) @@ -370,8 +369,7 @@ def from_spectral_image(path: str | Path) -> Specification_Fichet2021: channels = image_specification.channelnames for i, channel in enumerate(channels): - match = pattern_emissive.match(channel) - if match: + if (match := pattern_emissive.match(channel)) is not None: is_emissive = True component = match.group(1) @@ -382,8 +380,7 @@ def from_spectral_image(path: str | Path) -> Specification_Fichet2021: if len(components) > 1: is_polarised = True - match = pattern_bispectral.match(channel) - if match: + if (match := pattern_bispectral.match(channel)) is not None: is_bispectral = True input_multiplier, input_units = match.group(3, 4) @@ -396,8 +393,7 @@ def from_spectral_image(path: str | Path) -> Specification_Fichet2021: ) components[input_wavelength][output_wavelength] = i - match = pattern_reflective.match(channel) - if match: + if (match := pattern_reflective.match(channel)) is not None: multiplier, units = match.group(3, 4) wavelength = match_groups_to_nm(match.group(1), multiplier, units) components["T"][wavelength] = i diff --git a/colour/io/uprtek_sekonic.py b/colour/io/uprtek_sekonic.py index d976e8db4..4afcfa87f 100644 --- a/colour/io/uprtek_sekonic.py +++ b/colour/io/uprtek_sekonic.py @@ -398,8 +398,9 @@ def as_array(a: Any) -> list: attribute, tokens = row[0], row[1:] value = tokens[0] if len(tokens) == 1 else tokens - match = re.match(self._SPECTRAL_DATA_PATTERN, attribute) - if match: + if ( + match := re.match(self._SPECTRAL_DATA_PATTERN, attribute) + ) is not None: wavelength = match.group(1) if wavelength == self._SPECTRAL_SECTION: From ee4a1b212e52cca19e44e320540f4d60e8630b36 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Sun, 26 Jan 2025 12:20:37 +1300 Subject: [PATCH 2/3] Update various docstrings in `tasks.py` file. --- tasks.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tasks.py b/tasks.py index 3846fe18e..1b9d01845 100644 --- a/tasks.py +++ b/tasks.py @@ -271,8 +271,7 @@ def examples(ctx: Context, plots: bool = False) -> None: @task(formatting, quality, precommit, tests, examples) def preflight(ctx: Context) -> None: # noqa: ARG001 """ - Perform the preflight tasks, i.e., *formatting*, *tests*, *quality*, and - *examples*. + Perform the preflight tasks. Parameters ---------- @@ -361,8 +360,7 @@ def requirements(ctx: Context) -> None: @task(literalise, clean, preflight, docs, todo, requirements) def build(ctx: Context) -> None: """ - Build the project and runs dependency tasks, i.e., *docs*, *todo*, and - *preflight*. + Build the project and runs dependency tasks. Parameters ---------- From 8e66ed582bd95ee040b889607b21e98e0b92e548 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Sun, 26 Jan 2025 12:34:01 +1300 Subject: [PATCH 3/3] Update various docstrings. --- colour/algebra/extrapolation.py | 4 ++-- colour/io/tm2714.py | 34 ++++++++++++++-------------- colour/models/rgb/rgb_colourspace.py | 6 ++--- colour/notation/munsell.py | 2 +- colour/recovery/otsu2018.py | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/colour/algebra/extrapolation.py b/colour/algebra/extrapolation.py index 03f7e6432..f1dcf45fd 100644 --- a/colour/algebra/extrapolation.py +++ b/colour/algebra/extrapolation.py @@ -242,7 +242,7 @@ def left(self) -> Real | None: Returns ------- - :py:data:`None` or Real + Real or :py:data:`None` Left value to return for x < xi[0]. """ @@ -272,7 +272,7 @@ def right(self) -> Real | None: Returns ------- - :py:data:`None` or Real + Real or :py:data:`None` Right value to return for x > xi[-1]. """ diff --git a/colour/io/tm2714.py b/colour/io/tm2714.py index db6d7c96f..5ec5847be 100644 --- a/colour/io/tm2714.py +++ b/colour/io/tm2714.py @@ -257,7 +257,7 @@ def manufacturer(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Manufacturer. """ @@ -287,7 +287,7 @@ def catalog_number(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Catalog number. """ @@ -317,7 +317,7 @@ def description(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Description. """ @@ -347,7 +347,7 @@ def document_creator(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Document creator. """ @@ -377,7 +377,7 @@ def unique_identifier(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Unique identifier. """ @@ -407,7 +407,7 @@ def measurement_equipment(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Measurement equipment. """ @@ -437,7 +437,7 @@ def laboratory(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Laboratory. """ @@ -467,7 +467,7 @@ def report_number(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Report number. """ @@ -497,7 +497,7 @@ def report_date(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Report date. """ @@ -527,7 +527,7 @@ def document_creation_date(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Document creation date. """ @@ -557,7 +557,7 @@ def comments(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Comments. """ @@ -1025,7 +1025,7 @@ def path(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Path. """ @@ -1104,7 +1104,7 @@ def spectral_quantity( Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Spectral quantity. """ @@ -1171,7 +1171,7 @@ def reflection_geometry( Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Reflection geometry. """ @@ -1222,7 +1222,7 @@ def transmission_geometry( Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Transmission geometry. """ @@ -1255,7 +1255,7 @@ def bandwidth_FWHM(self) -> float | None: Returns ------- - :py:data:`None` or :class:`float` + :class:`float` or :py:data:`None` Full-width half-maximum bandwidth. """ @@ -1288,7 +1288,7 @@ def bandwidth_corrected(self) -> bool | None: Returns ------- - :py:data:`None` or :class:`bool` + :class:`bool` or :py:data:`None` Whether bandwidth correction has been applied to the measured data. """ diff --git a/colour/models/rgb/rgb_colourspace.py b/colour/models/rgb/rgb_colourspace.py index 32aab325f..f2aae7528 100644 --- a/colour/models/rgb/rgb_colourspace.py +++ b/colour/models/rgb/rgb_colourspace.py @@ -389,7 +389,7 @@ def whitepoint_name(self) -> str | None: Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` *RGB* colourspace whitepoint name. """ @@ -506,7 +506,7 @@ def cctf_encoding(self) -> Callable | None: Returns ------- - :py:data:`None` or Callable + Callable or :py:data:`None` Encoding colour component transfer function (Encoding CCTF) / opto-electronic transfer function (OETF). """ @@ -540,7 +540,7 @@ def cctf_decoding(self) -> Callable | None: Returns ------- - :py:data:`None` or Callable + Callable or :py:data:`None` Decoding colour component transfer function (Decoding CCTF) / electro-optical transfer function (EOTF). """ diff --git a/colour/notation/munsell.py b/colour/notation/munsell.py index c774f787e..57899bade 100644 --- a/colour/notation/munsell.py +++ b/colour/notation/munsell.py @@ -2007,7 +2007,7 @@ def interpolation_method_from_renotation_ovoid( Returns ------- - :py:data:`None` or :class:`str` + :class:`str` or :py:data:`None` Interpolation method. References diff --git a/colour/recovery/otsu2018.py b/colour/recovery/otsu2018.py index aebfb22c3..bdaaa03b7 100644 --- a/colour/recovery/otsu2018.py +++ b/colour/recovery/otsu2018.py @@ -768,7 +768,7 @@ def mean(self) -> NDArrayFloat | None: Returns ------- - :py:data:`None` or :class:`numpy.ndarray` + :class:`numpy.ndarray` or :py:data:`None` Mean distribution. """