Improve formatting in core files (#135256)

* Adjust core files formatting

* Adjust translations script
This commit is contained in:
epenet
2025-01-10 09:08:37 +01:00
committed by GitHub
parent 823feae0f9
commit 5df7092f41
20 changed files with 34 additions and 38 deletions

View File

@ -119,7 +119,7 @@ def _extract_backup(
Path(
tempdir,
"extracted",
f"homeassistant.tar{'.gz' if backup_meta["compressed"] else ''}",
f"homeassistant.tar{'.gz' if backup_meta['compressed'] else ''}",
),
gzip=backup_meta["compressed"],
key=password_to_key(restore_content.password)

View File

@ -691,10 +691,7 @@ class ConfigEntry(Generic[_DataT]):
self._tries += 1
ready_message = f"ready yet: {message}" if message else "ready yet"
_LOGGER.debug(
(
"Config entry '%s' for %s integration not %s; Retrying in %d"
" seconds"
),
"Config entry '%s' for %s integration not %s; Retrying in %d seconds",
self.title,
self.domain,
ready_message,

View File

@ -1153,8 +1153,7 @@ class HomeAssistant:
await self.async_block_till_done()
except TimeoutError:
_LOGGER.warning(
"Timed out waiting for integrations to stop, the shutdown will"
" continue"
"Timed out waiting for integrations to stop, the shutdown will continue"
)
self._async_log_running_tasks("stop integrations")

View File

@ -154,7 +154,7 @@ def _format_err[*_Ts](
return (
# Functions wrapped in partial do not have a __name__
f"Exception in {getattr(target, "__name__", None) or target} "
f"Exception in {getattr(target, '__name__', None) or target} "
f"when dispatching '{signal}': {args}"
)

View File

@ -666,7 +666,7 @@ def _validate_item(
# In HA Core 2025.10, we should fail if unique_id is not a string
report_issue = async_suggest_report_issue(hass, integration_domain=platform)
_LOGGER.error(
("'%s' from integration %s has a non string unique_id" " '%s', please %s"),
"'%s' from integration %s has a non string unique_id '%s', please %s",
domain,
platform,
unique_id,

View File

@ -1770,7 +1770,7 @@ class Script:
f"{self.domain}.{self.name} which is already running "
"in the current execution path; "
"Traceback (most recent call last):\n"
f"{"\n".join(formatted_stack)}",
f"{'\n'.join(formatted_stack)}",
level=logging.WARNING,
)
return None

View File

@ -133,8 +133,7 @@ def _validate_option_or_feature(option_or_feature: str, label: str) -> Any:
domain, enum, option = option_or_feature.split(".", 2)
except ValueError as exc:
raise vol.Invalid(
f"Invalid {label} '{option_or_feature}', expected "
"<domain>.<enum>.<member>"
f"Invalid {label} '{option_or_feature}', expected <domain>.<enum>.<member>"
) from exc
base_components = _base_components()

View File

@ -1765,8 +1765,7 @@ def async_suggest_report_issue(
if not integration_domain:
return "report it to the custom integration author"
return (
f"report it to the author of the '{integration_domain}' "
"custom integration"
f"report it to the author of the '{integration_domain}' custom integration"
)
return f"create a bug report at {issue_tracker}"

View File

@ -94,7 +94,8 @@ def raise_for_blocking_call(
if found_frame is None:
raise RuntimeError( # noqa: TRY200
f"Caught blocking call to {func.__name__} with args {mapped_args.get("args")} "
f"Caught blocking call to {func.__name__} "
f"with args {mapped_args.get('args')} "
f"in {offender_filename}, line {offender_lineno}: {offender_line} "
"inside the event loop; "
"This is causing stability issues. "

View File

@ -231,8 +231,7 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
if integrations_path.read_text() != content + "\n":
config.add_error(
"config_flow",
"File integrations.json is not up to date. "
"Run python3 -m script.hassfest",
"File integrations.json is not up to date. Run python3 -m script.hassfest",
fixable=True,
)

View File

@ -55,8 +55,7 @@ def validate(
config_flow = ast_parse_module(config_flow_file)
if not (_has_discovery_function(config_flow)):
return [
f"Integration is missing one of {CONFIG_FLOW_STEPS} "
f"in {config_flow_file}"
f"Integration is missing one of {CONFIG_FLOW_STEPS} in {config_flow_file}"
]
return None

View File

@ -510,8 +510,8 @@ def validate_translation_file( # noqa: C901
):
integration.add_error(
"translations",
"Don't specify title in translation strings if it's a brand "
"name or add exception to ALLOW_NAME_TRANSLATION",
"Don't specify title in translation strings if it's "
"a brand name or add exception to ALLOW_NAME_TRANSLATION",
)
if config.specific_integrations:
@ -532,12 +532,15 @@ def validate_translation_file( # noqa: C901
if parts or key not in search:
integration.add_error(
"translations",
f"{reference['source']} contains invalid reference {reference['ref']}: Could not find {key}",
f"{reference['source']} contains invalid reference"
f"{reference['ref']}: Could not find {key}",
)
elif match := re.match(RE_REFERENCE, search[key]):
integration.add_error(
"translations",
f"Lokalise supports only one level of references: \"{reference['source']}\" should point to directly to \"{match.groups()[0]}\"",
"Lokalise supports only one level of references: "
f'"{reference["source"]}" should point to directly '
f'to "{match.groups()[0]}"',
)

View File

@ -93,7 +93,7 @@ def gather_new_integration(determine_auth: bool) -> Info:
"prompt": (
f"""How will your integration gather data?
Valid values are {', '.join(SUPPORTED_IOT_CLASSES)}
Valid values are {", ".join(SUPPORTED_IOT_CLASSES)}
More info @ https://developers.home-assistant.io/docs/creating_integration_manifest#iot-class
"""

View File

@ -777,7 +777,7 @@ async def _check_config_flow_result_translations(
translation_errors,
category,
integration,
f"{key_prefix}abort.{result["reason"]}",
f"{key_prefix}abort.{result['reason']}",
result["description_placeholders"],
)

View File

@ -580,7 +580,7 @@ async def hass(
exceptions.append(
Exception(
"Received exception handler without exception, "
f"but with message: {context["message"]}"
f"but with message: {context['message']}"
)
)
orig_exception_handler(loop, context)

View File

@ -74,7 +74,7 @@ def test_load_translations_files_by_language(
"name": "Other 4",
"unit_of_measurement": "quantities",
},
"outlet": {"name": "Outlet " "{placeholder}"},
"outlet": {"name": "Outlet {placeholder}"},
}
},
"something": "else",

View File

@ -376,7 +376,7 @@ def override_syrupy_finish(self: SnapshotSession) -> int:
with open(".pytest_syrupy_worker_count", "w", encoding="utf-8") as f:
f.write(os.getenv("PYTEST_XDIST_WORKER_COUNT"))
with open(
f".pytest_syrupy_{os.getenv("PYTEST_XDIST_WORKER")}_result",
f".pytest_syrupy_{os.getenv('PYTEST_XDIST_WORKER')}_result",
"w",
encoding="utf-8",
) as f: