mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Update string formatting to use f-string on core codebase (#125988)
* Update string formatting to use f-string on core codebase * Small change given review feedback
This commit is contained in:
parent
7ba9d1fe65
commit
28ece89272
@ -151,11 +151,11 @@ def _format_err[*_Ts](
|
|||||||
*args: Any,
|
*args: Any,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Format error message."""
|
"""Format error message."""
|
||||||
return "Exception in {} when dispatching '{}': {}".format(
|
|
||||||
|
return (
|
||||||
# Functions wrapped in partial do not have a __name__
|
# Functions wrapped in partial do not have a __name__
|
||||||
getattr(target, "__name__", None) or str(target),
|
f"Exception in {getattr(target, "__name__", None) or target} "
|
||||||
signal,
|
f"when dispatching '{signal}': {args}"
|
||||||
args,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,8 +196,8 @@ def async_create_catching_coro[_T](
|
|||||||
trace = traceback.extract_stack()
|
trace = traceback.extract_stack()
|
||||||
return catch_log_coro_exception(
|
return catch_log_coro_exception(
|
||||||
target,
|
target,
|
||||||
lambda: "Exception in {} called from\n {}".format(
|
lambda: (
|
||||||
target.__name__,
|
f"Exception in {target.__name__} called from\n"
|
||||||
"".join(traceback.format_list(trace[:-1])),
|
+ "".join(traceback.format_list(trace[:-1]))
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -57,7 +57,9 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
for key in sorted(msg):
|
for key in sorted(msg):
|
||||||
print("\n{}\n - {}".format(key, "\n - ".join(msg[key])))
|
print(f"\n{key}")
|
||||||
|
for val in msg[key]:
|
||||||
|
print(f" - {val}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -109,14 +109,16 @@ async def test_if_fires_on_state_change(
|
|||||||
hass.states.async_set("NEW_DOMAIN.entity", STATE_ON)
|
hass.states.async_set("NEW_DOMAIN.entity", STATE_ON)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(service_calls) == 1
|
assert len(service_calls) == 1
|
||||||
assert service_calls[0].data[
|
assert (
|
||||||
"some"
|
service_calls[0].data["some"]
|
||||||
] == "turn_on - device - {} - off - on - None - 0".format("NEW_DOMAIN.entity")
|
== "turn_on - device - NEW_DOMAIN.entity - off - on - None - 0"
|
||||||
|
)
|
||||||
|
|
||||||
# Fake that the entity is turning off.
|
# Fake that the entity is turning off.
|
||||||
hass.states.async_set("NEW_DOMAIN.entity", STATE_OFF)
|
hass.states.async_set("NEW_DOMAIN.entity", STATE_OFF)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(service_calls) == 2
|
assert len(service_calls) == 2
|
||||||
assert service_calls[1].data[
|
assert (
|
||||||
"some"
|
service_calls[1].data["some"]
|
||||||
] == "turn_off - device - {} - on - off - None - 0".format("NEW_DOMAIN.entity")
|
== "turn_off - device - NEW_DOMAIN.entity - on - off - None - 0"
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user