Skip to content

Commit

Permalink
Fix ruff complaints in files unrelated to this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
enourbakhsh committed Dec 11, 2024
1 parent 6bf27ec commit bdc8aa5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions python/lsst/pex/config/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def format(config, name=None, writeSourceLine=True, prefix="", verbose=False):
if writeSourceLine:
line.append(
[
"%s" % ("%s:%d" % (frame.filename, frame.lineno)),
f"{frame.filename}:{frame.lineno}",
"FILE",
]
)
Expand Down Expand Up @@ -252,14 +252,14 @@ def format(config, name=None, writeSourceLine=True, prefix="", verbose=False):
fullname = f"{config._name}.{name}" if config._name is not None else name
msg.append(_colorize(re.sub(r"^root\.", "", fullname), "NAME"))
for value, output in outputs:
line = prefix + _colorize("%-*s" % (valueLength, value), "VALUE") + " "
line = prefix + _colorize(f"{value:<{valueLength}}", "VALUE") + " "
for i, vt in enumerate(output):
if writeSourceLine:
vt[0][0] = "%-*s" % (sourceLength, vt[0][0])
vt[0][0] = f"{vt[0][0]:<{sourceLength}}"

Check warning on line 258 in python/lsst/pex/config/history.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pex/config/history.py#L258

Added line #L258 was not covered by tests

output[i] = " ".join([_colorize(v, t) for v, t in vt])

line += ("\n%*s" % (valueLength + 1, "")).join(output)
line += ("\n" + f"{'':>{valueLength + 1}}").join(output)
msg.append(line)

return "\n".join(msg)
25 changes: 12 additions & 13 deletions python/lsst/pex/config/listField.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ def validateItem(self, i, x):
`ListField.itemCheck` method.
"""
if not isinstance(x, self._field.itemtype) and x is not None:
msg = "Item at position %d with value %s is of incorrect type %s. Expected %s" % (
i,
x,
_typeStr(x),
_typeStr(self._field.itemtype),
msg = (
f"Item at position {i} with value {x} is of incorrect type {_typeStr(x)}. "
f"Expected {_typeStr(self._field.itemtype)}"
)
raise FieldValidationError(self._field, self._config, msg)

if self._field.itemCheck is not None and not self._field.itemCheck(x):
msg = "Item at position %d is not a valid value: %s" % (i, x)
msg = f"Item at position {i} is not a valid value: {x}"
raise FieldValidationError(self._field, self._config, msg)

def list(self):
Expand Down Expand Up @@ -329,15 +327,15 @@ def __init__(
raise ValueError(f"Unsupported dtype {_typeStr(dtype)}")
if length is not None:
if length <= 0:
raise ValueError("'length' (%d) must be positive" % length)
raise ValueError(f"'length' ({length}) must be positive")
minLength = None
maxLength = None
else:
if maxLength is not None and maxLength <= 0:
raise ValueError("'maxLength' (%d) must be positive" % maxLength)
raise ValueError(f"'maxLength' ({maxLength}) must be positive")
if minLength is not None and maxLength is not None and minLength > maxLength:
raise ValueError(
"'maxLength' (%d) must be at least as large as 'minLength' (%d)" % (maxLength, minLength)
f"'maxLength' ({maxLength}) must be at least as large as 'minLength' ({minLength})"
)

if listCheck is not None and not hasattr(listCheck, "__call__"):
Expand Down Expand Up @@ -412,13 +410,13 @@ def validate(self, instance):
if value is not None:
lenValue = len(value)
if self.length is not None and not lenValue == self.length:
msg = "Required list length=%d, got length=%d" % (self.length, lenValue)
msg = f"Required list length={self.length}, got length={lenValue}"

Check warning on line 413 in python/lsst/pex/config/listField.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pex/config/listField.py#L413

Added line #L413 was not covered by tests
raise FieldValidationError(self, instance, msg)
elif self.minLength is not None and lenValue < self.minLength:
msg = "Minimum allowed list length=%d, got length=%d" % (self.minLength, lenValue)
msg = f"Minimum allowed list length={self.minLength}, got length={lenValue}"

Check warning on line 416 in python/lsst/pex/config/listField.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pex/config/listField.py#L416

Added line #L416 was not covered by tests
raise FieldValidationError(self, instance, msg)
elif self.maxLength is not None and lenValue > self.maxLength:
msg = "Maximum allowed list length=%d, got length=%d" % (self.maxLength, lenValue)
msg = f"Maximum allowed list length={self.maxLength}, got length={lenValue}"

Check warning on line 419 in python/lsst/pex/config/listField.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pex/config/listField.py#L419

Added line #L419 was not covered by tests
raise FieldValidationError(self, instance, msg)
elif self.listCheck is not None and not self.listCheck(value):
msg = f"{value} is not a valid value"
Expand Down Expand Up @@ -510,8 +508,9 @@ def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
equal = True
for n, v1, v2 in zip(range(len(l1)), l1, l2):
result = compareScalars(
"%s[%d]" % (name, n), v1, v2, dtype=self.dtype, rtol=rtol, atol=atol, output=output
f"{name}[{n}]", v1, v2, dtype=self.dtype, rtol=rtol, atol=atol, output=output
)

if not result and shortcut:
return False
equal = equal and result
Expand Down

0 comments on commit bdc8aa5

Please sign in to comment.