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:
committed by
Paulus Schoutsen
parent
5ad209c6fd
commit
fa4fa30461
@@ -182,7 +182,7 @@ def gather_requirements_from_modules(errors, reqs):
|
||||
try:
|
||||
module = importlib.import_module(package)
|
||||
except ImportError as err:
|
||||
print("{}: {}".format(package.replace(".", "/") + ".py", err))
|
||||
print("{}.py: {}".format(package.replace(".", "/"), err))
|
||||
errors.append(package)
|
||||
continue
|
||||
|
||||
@@ -288,8 +288,8 @@ def diff_file(filename, content):
|
||||
"""Diff a file."""
|
||||
return list(
|
||||
difflib.context_diff(
|
||||
[line + "\n" for line in Path(filename).read_text().split("\n")],
|
||||
[line + "\n" for line in content.split("\n")],
|
||||
[f"{line}\n" for line in Path(filename).read_text().split("\n")],
|
||||
[f"{line}\n" for line in content.split("\n")],
|
||||
filename,
|
||||
"generated",
|
||||
)
|
||||
|
||||
@@ -222,9 +222,8 @@ def validate_dependencies(
|
||||
):
|
||||
integration.add_error(
|
||||
"dependencies",
|
||||
"Using component {} but it's not in 'dependencies' or 'after_dependencies'".format(
|
||||
domain
|
||||
),
|
||||
f"Using component {domain} but it's not in 'dependencies' "
|
||||
"or 'after_dependencies'",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@ class Integration:
|
||||
init = fil / "__init__.py"
|
||||
if not init.exists():
|
||||
print(
|
||||
"Warning: {} missing, skipping directory. "
|
||||
f"Warning: {init} missing, skipping directory. "
|
||||
"If this is your development environment, "
|
||||
"you can safely delete this folder.".format(init)
|
||||
"you can safely delete this folder."
|
||||
)
|
||||
continue
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ def main():
|
||||
if hasattr(module, "CONFIG_SCHEMA"):
|
||||
add_msg(
|
||||
"WARNING",
|
||||
"Module {} contains PLATFORM and CONFIG "
|
||||
"schemas".format(module_name),
|
||||
f"Module {module_name} contains PLATFORM and CONFIG schemas",
|
||||
)
|
||||
add_msg("PLATFORM SCHEMA", module_name)
|
||||
continue
|
||||
@@ -52,7 +51,7 @@ def main():
|
||||
schema_type, schema = _identify_config_schema(module)
|
||||
|
||||
add_msg(
|
||||
"CONFIG_SCHEMA " + str(schema_type),
|
||||
f"CONFIG_SCHEMA {schema_type}",
|
||||
module_name + " " + color("cyan", str(schema)[:60]),
|
||||
)
|
||||
|
||||
|
||||
@@ -76,8 +76,7 @@ async def async_exec(*args, display=False):
|
||||
proc = await asyncio.create_subprocess_exec(*args, **kwargs)
|
||||
except FileNotFoundError as err:
|
||||
printc(
|
||||
FAIL,
|
||||
"Could not execute {}. Did you install test requirements?".format(args[0]),
|
||||
FAIL, f"Could not execute {args[0]}. Did you install test requirements?",
|
||||
)
|
||||
raise err
|
||||
|
||||
@@ -202,7 +201,7 @@ async def main():
|
||||
elif parts[-1] == "__main__.py":
|
||||
parts[-1] = "test_main.py"
|
||||
else:
|
||||
parts[-1] = "test_" + parts[-1]
|
||||
parts[-1] = f"test_{parts[-1]}"
|
||||
fname = "/".join(parts)
|
||||
if os.path.isfile(fname):
|
||||
test_files.add(fname)
|
||||
|
||||
Reference in New Issue
Block a user