Skip to content

Commit

Permalink
Use walrus operator for re.match usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Jan 13, 2025
1 parent 9c00f80 commit 8b440b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
12 changes: 4 additions & 8 deletions colour/io/fichet2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions colour/io/uprtek_sekonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8b440b9

Please sign in to comment.