diff --git a/python/lsst/pex/config/history.py b/python/lsst/pex/config/history.py index 2800f7d..6a1e77b 100644 --- a/python/lsst/pex/config/history.py +++ b/python/lsst/pex/config/history.py @@ -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", ] ) @@ -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}}" 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) diff --git a/python/lsst/pex/config/listField.py b/python/lsst/pex/config/listField.py index 2117bb0..809c6d2 100644 --- a/python/lsst/pex/config/listField.py +++ b/python/lsst/pex/config/listField.py @@ -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): @@ -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__"): @@ -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}" 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}" 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}" raise FieldValidationError(self, instance, msg) elif self.listCheck is not None and not self.listCheck(value): msg = f"{value} is not a valid value" @@ -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