From bff663b3c180fdc9af8d94803b80ac194d3126b2 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 9 Jul 2024 21:12:03 +0200 Subject: [PATCH] Improve type hints in recorder result_processor (#121593) --- homeassistant/components/recorder/db_schema.py | 4 ++-- tests/components/recorder/db_schema_30.py | 3 ++- tests/components/recorder/db_schema_32.py | 3 ++- tests/components/recorder/db_schema_42.py | 4 ++-- tests/components/recorder/db_schema_43.py | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/recorder/db_schema.py b/homeassistant/components/recorder/db_schema.py index 57f113b779e..8d4cc29d9be 100644 --- a/homeassistant/components/recorder/db_schema.py +++ b/homeassistant/components/recorder/db_schema.py @@ -178,7 +178,7 @@ def compile_char_one(type_: TypeDecorator, compiler: Any, **kw: Any) -> str: class FAST_PYSQLITE_DATETIME(sqlite.DATETIME): """Use ciso8601 to parse datetimes instead of sqlalchemy built-in regex.""" - def result_processor(self, dialect, coltype): # type: ignore[no-untyped-def] + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable | None: """Offload the datetime parsing to ciso8601.""" return lambda value: None if value is None else ciso8601.parse_datetime(value) @@ -186,7 +186,7 @@ class FAST_PYSQLITE_DATETIME(sqlite.DATETIME): class NativeLargeBinary(LargeBinary): """A faster version of LargeBinary for engines that support python bytes natively.""" - def result_processor(self, dialect, coltype): # type: ignore[no-untyped-def] + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable | None: """No conversion needed for engines that support native bytes.""" return None diff --git a/tests/components/recorder/db_schema_30.py b/tests/components/recorder/db_schema_30.py index b82213cbc89..2668f610dfd 100644 --- a/tests/components/recorder/db_schema_30.py +++ b/tests/components/recorder/db_schema_30.py @@ -33,6 +33,7 @@ from sqlalchemy import ( type_coerce, ) from sqlalchemy.dialects import mysql, oracle, postgresql, sqlite +from sqlalchemy.engine.interfaces import Dialect from sqlalchemy.orm import aliased, declarative_base, relationship from sqlalchemy.orm.session import Session @@ -109,7 +110,7 @@ STATES_CONTEXT_ID_BIN_INDEX = "ix_states_context_id_bin" class FAST_PYSQLITE_DATETIME(sqlite.DATETIME): # type: ignore[misc] """Use ciso8601 to parse datetimes instead of sqlalchemy built-in regex.""" - def result_processor(self, dialect, coltype): # type: ignore[no-untyped-def] + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable | None: """Offload the datetime parsing to ciso8601.""" return lambda value: None if value is None else ciso8601.parse_datetime(value) diff --git a/tests/components/recorder/db_schema_32.py b/tests/components/recorder/db_schema_32.py index 15b56e2fc86..60f4f733ec0 100644 --- a/tests/components/recorder/db_schema_32.py +++ b/tests/components/recorder/db_schema_32.py @@ -33,6 +33,7 @@ from sqlalchemy import ( type_coerce, ) from sqlalchemy.dialects import mysql, oracle, postgresql, sqlite +from sqlalchemy.engine.interfaces import Dialect from sqlalchemy.orm import aliased, declarative_base, relationship from sqlalchemy.orm.session import Session @@ -109,7 +110,7 @@ STATES_CONTEXT_ID_BIN_INDEX = "ix_states_context_id_bin" class FAST_PYSQLITE_DATETIME(sqlite.DATETIME): # type: ignore[misc] """Use ciso8601 to parse datetimes instead of sqlalchemy built-in regex.""" - def result_processor(self, dialect, coltype): # type: ignore[no-untyped-def] + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable | None: """Offload the datetime parsing to ciso8601.""" return lambda value: None if value is None else ciso8601.parse_datetime(value) diff --git a/tests/components/recorder/db_schema_42.py b/tests/components/recorder/db_schema_42.py index c0dfc70571d..99bdbb28f2c 100644 --- a/tests/components/recorder/db_schema_42.py +++ b/tests/components/recorder/db_schema_42.py @@ -171,7 +171,7 @@ def compile_char_one(type_: TypeDecorator, compiler: Any, **kw: Any) -> str: class FAST_PYSQLITE_DATETIME(sqlite.DATETIME): """Use ciso8601 to parse datetimes instead of sqlalchemy built-in regex.""" - def result_processor(self, dialect, coltype): # type: ignore[no-untyped-def] + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable | None: """Offload the datetime parsing to ciso8601.""" return lambda value: None if value is None else ciso8601.parse_datetime(value) @@ -179,7 +179,7 @@ class FAST_PYSQLITE_DATETIME(sqlite.DATETIME): class NativeLargeBinary(LargeBinary): """A faster version of LargeBinary for engines that support python bytes natively.""" - def result_processor(self, dialect, coltype): # type: ignore[no-untyped-def] + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable | None: """No conversion needed for engines that support native bytes.""" return None diff --git a/tests/components/recorder/db_schema_43.py b/tests/components/recorder/db_schema_43.py index 896c995f364..26d8ecd6856 100644 --- a/tests/components/recorder/db_schema_43.py +++ b/tests/components/recorder/db_schema_43.py @@ -180,7 +180,7 @@ def compile_char_one(type_: TypeDecorator, compiler: Any, **kw: Any) -> str: class FAST_PYSQLITE_DATETIME(sqlite.DATETIME): """Use ciso8601 to parse datetimes instead of sqlalchemy built-in regex.""" - def result_processor(self, dialect, coltype): # type: ignore[no-untyped-def] + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable | None: """Offload the datetime parsing to ciso8601.""" return lambda value: None if value is None else ciso8601.parse_datetime(value) @@ -188,7 +188,7 @@ class FAST_PYSQLITE_DATETIME(sqlite.DATETIME): class NativeLargeBinary(LargeBinary): """A faster version of LargeBinary for engines that support python bytes natively.""" - def result_processor(self, dialect, coltype): # type: ignore[no-untyped-def] + def result_processor(self, dialect: Dialect, coltype: Any) -> Callable | None: """No conversion needed for engines that support native bytes.""" return None