1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Use literal string interpolation in core (f-strings) (#26166)

This commit is contained in:
Franck Nijhof
2019-08-23 18:53:33 +02:00
committed by Paulus Schoutsen
parent 1efa29d6ff
commit decf13b948
67 changed files with 180 additions and 246 deletions

View File

@@ -165,10 +165,7 @@ class Integration:
continue
return cls(
hass,
"{}.{}".format(root_module.__name__, domain),
manifest_path.parent,
manifest,
hass, f"{root_module.__name__}.{domain}", manifest_path.parent, manifest
)
return None
@@ -229,16 +226,16 @@ class Integration:
def get_platform(self, platform_name: str) -> ModuleType:
"""Return a platform for an integration."""
cache = self.hass.data.setdefault(DATA_COMPONENTS, {})
full_name = "{}.{}".format(self.domain, platform_name)
full_name = f"{self.domain}.{platform_name}"
if full_name not in cache:
cache[full_name] = importlib.import_module(
"{}.{}".format(self.pkg_path, platform_name)
f"{self.pkg_path}.{platform_name}"
)
return cache[full_name] # type: ignore
def __repr__(self) -> str:
"""Text representation of class."""
return "<Integration {}: {}>".format(self.domain, self.pkg_path)
return f"<Integration {self.domain}: {self.pkg_path}>"
async def async_get_integration(hass: "HomeAssistant", domain: str) -> Integration:
@@ -312,7 +309,7 @@ class IntegrationNotFound(LoaderError):
def __init__(self, domain: str) -> None:
"""Initialize a component not found error."""
super().__init__("Integration {} not found.".format(domain))
super().__init__(f"Integration {domain} not found.")
self.domain = domain
@@ -321,9 +318,7 @@ class CircularDependency(LoaderError):
def __init__(self, from_domain: str, to_domain: str) -> None:
"""Initialize circular dependency error."""
super().__init__(
"Circular dependency detected: {} -> {}.".format(from_domain, to_domain)
)
super().__init__(f"Circular dependency detected: {from_domain} -> {to_domain}.")
self.from_domain = from_domain
self.to_domain = to_domain
@@ -350,7 +345,7 @@ def _load_file(
return None
cache = hass.data[DATA_COMPONENTS] = {}
for path in ("{}.{}".format(base, comp_or_platform) for base in base_paths):
for path in (f"{base}.{comp_or_platform}" for base in base_paths):
try:
module = importlib.import_module(path)
@@ -439,7 +434,7 @@ class Components:
component = _load_file(self._hass, comp_name, LOOKUP_PATHS)
if component is None:
raise ImportError("Unable to load {}".format(comp_name))
raise ImportError(f"Unable to load {comp_name}")
wrapped = ModuleWrapper(self._hass, component)
setattr(self, comp_name, wrapped)
@@ -457,7 +452,7 @@ class Helpers:
def __getattr__(self, helper_name: str) -> ModuleWrapper:
"""Fetch a helper."""
helper = importlib.import_module("homeassistant.helpers.{}".format(helper_name))
helper = importlib.import_module(f"homeassistant.helpers.{helper_name}")
wrapped = ModuleWrapper(self._hass, helper)
setattr(self, helper_name, wrapped)
return wrapped