Various string cleanups (#30435)

* Remove some unnecessary string concatenations

* Replace some simple str.formats with f-strings

* Replace some string concatenations with f-strings
This commit is contained in:
Ville Skyttä
2020-01-03 14:47:06 +01:00
committed by Paulus Schoutsen
parent 5ad209c6fd
commit fa4fa30461
105 changed files with 241 additions and 314 deletions
+2 -2
View File
@@ -232,8 +232,8 @@ def parse_time_expression(parameter: Any, min_value: int, max_value: int) -> Lis
for val in res:
if val < min_value or val > max_value:
raise ValueError(
"Time expression '{}': parameter {} out of range ({} to {})"
"".format(parameter, val, min_value, max_value)
f"Time expression '{parameter}': parameter {val} out of range "
f"({min_value} to {max_value})"
)
return res
+1 -1
View File
@@ -114,7 +114,7 @@ def save_yaml(fname: str, data: JSON_TYPE) -> None:
"""Save a YAML file."""
yaml = YAML(typ="rt")
yaml.indent(sequence=4, offset=2)
tmp_fname = fname + "__TEMP__"
tmp_fname = f"{fname}__TEMP__"
try:
try:
file_stat = os.stat(fname)
+4 -4
View File
@@ -107,7 +107,7 @@ class UnitSystem:
def temperature(self, temperature: float, from_unit: str) -> float:
"""Convert the given temperature to this unit system."""
if not isinstance(temperature, Number):
raise TypeError("{} is not a numeric value.".format(str(temperature)))
raise TypeError(f"{temperature!s} is not a numeric value.")
# type ignore: https://github.com/python/mypy/issues/7207
return temperature_util.convert( # type: ignore
@@ -117,7 +117,7 @@ class UnitSystem:
def length(self, length: Optional[float], from_unit: str) -> float:
"""Convert the given length to this unit system."""
if not isinstance(length, Number):
raise TypeError("{} is not a numeric value.".format(str(length)))
raise TypeError(f"{length!s} is not a numeric value.")
# type ignore: https://github.com/python/mypy/issues/7207
return distance_util.convert( # type: ignore
@@ -127,7 +127,7 @@ class UnitSystem:
def pressure(self, pressure: Optional[float], from_unit: str) -> float:
"""Convert the given pressure to this unit system."""
if not isinstance(pressure, Number):
raise TypeError("{} is not a numeric value.".format(str(pressure)))
raise TypeError(f"{pressure!s} is not a numeric value.")
# type ignore: https://github.com/python/mypy/issues/7207
return pressure_util.convert( # type: ignore
@@ -137,7 +137,7 @@ class UnitSystem:
def volume(self, volume: Optional[float], from_unit: str) -> float:
"""Convert the given volume to this unit system."""
if not isinstance(volume, Number):
raise TypeError("{} is not a numeric value.".format(str(volume)))
raise TypeError(f"{volume!s} is not a numeric value.")
# type ignore: https://github.com/python/mypy/issues/7207
return volume_util.convert( # type: ignore