From 3df91cfba59b350cabbcd3ca398b42acb914cd46 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 29 Dec 2024 17:16:11 +0100 Subject: [PATCH] Fix method subtyping [recorder] (#134212) --- homeassistant/components/recorder/db_schema.py | 8 ++++++-- homeassistant/components/recorder/migration.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/recorder/db_schema.py b/homeassistant/components/recorder/db_schema.py index 2afbed9cb75..cefce9c4e72 100644 --- a/homeassistant/components/recorder/db_schema.py +++ b/homeassistant/components/recorder/db_schema.py @@ -6,7 +6,7 @@ from collections.abc import Callable from datetime import datetime, timedelta import logging import time -from typing import Any, Final, Self, cast +from typing import Any, Final, Protocol, Self, cast import ciso8601 from fnv_hash_fast import fnv1a_32 @@ -233,10 +233,14 @@ CONTEXT_BINARY_TYPE = LargeBinary(CONTEXT_ID_BIN_MAX_LENGTH).with_variant( TIMESTAMP_TYPE = DOUBLE_TYPE +class _LiteralProcessorType(Protocol): + def __call__(self, value: Any) -> str: ... + + class JSONLiteral(JSON): """Teach SA how to literalize json.""" - def literal_processor(self, dialect: Dialect) -> Callable[[Any], str]: + def literal_processor(self, dialect: Dialect) -> _LiteralProcessorType: """Processor to convert a value to JSON.""" def process(value: Any) -> str: diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index 8c9252ba28b..6ae1e265901 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -2453,7 +2453,7 @@ class BaseMigration(ABC): self.migration_changes = migration_changes @abstractmethod - def migrate_data(self, instance: Recorder) -> bool: + def migrate_data(self, instance: Recorder, /) -> bool: """Migrate some data, return True if migration is completed.""" def _migrate_data(self, instance: Recorder) -> bool: -- GitLab