Small typing improvements (#126818)
* Add from __future__ import annotations * Use PEP 695 type aliases * Fix generator typingpull/126824/head
parent
cf803507d6
commit
c1b24e6ba2
|
@ -1,5 +1,7 @@
|
||||||
"""Media source for Google Photos."""
|
"""Media source for Google Photos."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
import logging
|
import logging
|
||||||
|
@ -46,7 +48,7 @@ class PhotosIdentifierType(StrEnum):
|
||||||
ALBUM = "a"
|
ALBUM = "a"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def of(cls, name: str) -> "PhotosIdentifierType":
|
def of(cls, name: str) -> PhotosIdentifierType:
|
||||||
"""Parse a PhotosIdentifierType by string value."""
|
"""Parse a PhotosIdentifierType by string value."""
|
||||||
for enum in PhotosIdentifierType:
|
for enum in PhotosIdentifierType:
|
||||||
if enum.value == name:
|
if enum.value == name:
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""Config flow for the html5 component."""
|
"""Config flow for the html5 component."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import binascii
|
import binascii
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
|
@ -42,7 +44,7 @@ class HTML5ConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_create_html5_entry(
|
def _async_create_html5_entry(
|
||||||
self: "HTML5ConfigFlow", data: dict[str, str]
|
self: HTML5ConfigFlow, data: dict[str, str]
|
||||||
) -> tuple[dict[str, str], ConfigFlowResult | None]:
|
) -> tuple[dict[str, str], ConfigFlowResult | None]:
|
||||||
"""Create an HTML5 entry."""
|
"""Create an HTML5 entry."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
@ -68,7 +70,7 @@ class HTML5ConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
return errors, flow_result
|
return errors, flow_result
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self: "HTML5ConfigFlow", user_input: dict[str, Any] | None = None
|
self: HTML5ConfigFlow, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
@ -92,7 +94,7 @@ class HTML5ConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(
|
async def async_step_import(
|
||||||
self: "HTML5ConfigFlow", import_config: dict
|
self: HTML5ConfigFlow, import_config: dict
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle config import from yaml."""
|
"""Handle config import from yaml."""
|
||||||
_, flow_result = self._async_create_html5_entry(import_config)
|
_, flow_result = self._async_create_html5_entry(import_config)
|
||||||
|
|
|
@ -19,8 +19,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
STORAGE_VERSION: Final = 1
|
STORAGE_VERSION: Final = 1
|
||||||
STORAGE_KEY: Final = f"{DOMAIN}/config_store.json"
|
STORAGE_KEY: Final = f"{DOMAIN}/config_store.json"
|
||||||
|
|
||||||
KNXPlatformStoreModel = dict[str, dict[str, Any]] # unique_id: configuration
|
type KNXPlatformStoreModel = dict[str, dict[str, Any]] # unique_id: configuration
|
||||||
KNXEntityStoreModel = dict[
|
type KNXEntityStoreModel = dict[
|
||||||
str, KNXPlatformStoreModel
|
str, KNXPlatformStoreModel
|
||||||
] # platform: KNXPlatformStoreModel
|
] # platform: KNXPlatformStoreModel
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ if TYPE_CHECKING:
|
||||||
from .entity import ZHAEntity
|
from .entity import ZHAEntity
|
||||||
from .update import ZHAFirmwareUpdateCoordinator
|
from .update import ZHAFirmwareUpdateCoordinator
|
||||||
|
|
||||||
_LogFilterType = Filter | Callable[[LogRecord], bool]
|
type _LogFilterType = Filter | Callable[[LogRecord], bool]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
"""Tests for the KNX integration."""
|
"""Tests for the KNX integration."""
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Callable, Coroutine
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
KnxEntityGenerator = Callable[..., Awaitable[er.RegistryEntry]]
|
type KnxEntityGenerator = Callable[..., Coroutine[Any, Any, er.RegistryEntry]]
|
||||||
|
|
|
@ -310,7 +310,7 @@ def mock_smile_p1_2() -> Generator[MagicMock]:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_smile_legacy_anna() -> Generator[None, MagicMock, None]:
|
def mock_smile_legacy_anna() -> Generator[MagicMock]:
|
||||||
"""Create a Mock legacy Anna environment for testing exceptions."""
|
"""Create a Mock legacy Anna environment for testing exceptions."""
|
||||||
chosen_env = "legacy_anna"
|
chosen_env = "legacy_anna"
|
||||||
with patch(
|
with patch(
|
||||||
|
|
Loading…
Reference in New Issue