1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-07 12:23:47 +01:00

[core] Add typing to some core files (#10843)

This commit is contained in:
Jesse Hills
2025-09-24 02:32:13 +12:00
committed by GitHub
parent 3b40172073
commit 3b20969171
4 changed files with 181 additions and 69 deletions

View File

@@ -1,19 +1,30 @@
import collections
from collections.abc import Callable
import io
import logging
from pathlib import Path
import re
import subprocess
import sys
from typing import Any
from typing import TYPE_CHECKING, Any
from esphome import const
_LOGGER = logging.getLogger(__name__)
if TYPE_CHECKING:
from esphome.config_validation import Schema
from esphome.cpp_generator import MockObjClass
class RegistryEntry:
def __init__(self, name, fun, type_id, schema):
def __init__(
self,
name: str,
fun: Callable[..., Any],
type_id: "MockObjClass",
schema: "Schema",
):
self.name = name
self.fun = fun
self.type_id = type_id
@@ -38,8 +49,8 @@ class Registry(dict[str, RegistryEntry]):
self.base_schema = base_schema or {}
self.type_id_key = type_id_key
def register(self, name, type_id, schema):
def decorator(fun):
def register(self, name: str, type_id: "MockObjClass", schema: "Schema"):
def decorator(fun: Callable[..., Any]):
self[name] = RegistryEntry(name, fun, type_id, schema)
return fun
@@ -47,8 +58,8 @@ class Registry(dict[str, RegistryEntry]):
class SimpleRegistry(dict):
def register(self, name, data):
def decorator(fun):
def register(self, name: str, data: Any):
def decorator(fun: Callable[..., Any]):
self[name] = (fun, data)
return fun