Improve typing [util.decorator] (#67087)

This commit is contained in:
Marc Mueller 2022-02-23 20:58:42 +01:00 committed by GitHub
parent 46c2bd0eb0
commit ec980a574b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 59 additions and 38 deletions

View file

@ -3,7 +3,7 @@ from __future__ import annotations
import asyncio
from collections import defaultdict
from collections.abc import Callable, Coroutine
from collections.abc import Callable
import logging
import socket
import sys
@ -337,9 +337,7 @@ def _gw_callback_factory(
_LOGGER.debug("Node update: node %s child %s", msg.node_id, msg.child_id)
msg_type = msg.gateway.const.MessageType(msg.type)
msg_handler: Callable[
[HomeAssistant, GatewayId, Message], Coroutine[Any, Any, None]
] | None = HANDLERS.get(msg_type.name)
msg_handler = HANDLERS.get(msg_type.name)
if msg_handler is None:
return

View file

@ -1,6 +1,9 @@
"""Handle MySensors messages."""
from __future__ import annotations
from collections.abc import Callable, Coroutine
from typing import Any
from mysensors import Message
from homeassistant.const import Platform
@ -12,7 +15,9 @@ from .const import CHILD_CALLBACK, NODE_CALLBACK, DevId, GatewayId
from .device import get_mysensors_devices
from .helpers import discover_mysensors_platform, validate_set_msg
HANDLERS = decorator.Registry()
HANDLERS: decorator.Registry[
str, Callable[[HomeAssistant, GatewayId, Message], Coroutine[Any, Any, None]]
] = decorator.Registry()
@HANDLERS.register("set")

View file

@ -31,7 +31,9 @@ from .const import (
)
_LOGGER = logging.getLogger(__name__)
SCHEMAS = Registry()
SCHEMAS: Registry[
tuple[str, str], Callable[[BaseAsyncGateway, ChildSensor, ValueType], vol.Schema]
] = Registry()
@callback