mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Cleanup deprecated typing helpers (#158806)
This commit is contained in:
@@ -2,18 +2,10 @@
|
||||
|
||||
from collections.abc import Mapping
|
||||
from enum import Enum
|
||||
from functools import partial
|
||||
from typing import Any, Never
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from .deprecation import (
|
||||
DeferredDeprecatedAlias,
|
||||
all_with_deprecated_constants,
|
||||
check_if_deprecated_constant,
|
||||
dir_with_deprecated_constants,
|
||||
)
|
||||
|
||||
type GPSType = tuple[float, float]
|
||||
type ConfigType = dict[str, Any]
|
||||
type DiscoveryInfoType = dict[str, Any]
|
||||
@@ -35,32 +27,3 @@ class UndefinedType(Enum):
|
||||
|
||||
|
||||
UNDEFINED = UndefinedType._singleton # noqa: SLF001
|
||||
|
||||
|
||||
def _deprecated_typing_helper(attr: str) -> DeferredDeprecatedAlias:
|
||||
"""Help to make a DeferredDeprecatedAlias."""
|
||||
|
||||
def value_fn() -> Any:
|
||||
import homeassistant.core # noqa: PLC0415
|
||||
|
||||
return getattr(homeassistant.core, attr)
|
||||
|
||||
return DeferredDeprecatedAlias(value_fn, f"homeassistant.core.{attr}", "2025.5")
|
||||
|
||||
|
||||
# The following types should not used and
|
||||
# are not present in the core code base.
|
||||
# They are kept in order not to break custom integrations
|
||||
# that may rely on them.
|
||||
# Deprecated as of 2024.5 use types from homeassistant.core instead.
|
||||
_DEPRECATED_ContextType = _deprecated_typing_helper("Context")
|
||||
_DEPRECATED_EventType = _deprecated_typing_helper("Event")
|
||||
_DEPRECATED_HomeAssistantType = _deprecated_typing_helper("HomeAssistant")
|
||||
_DEPRECATED_ServiceCallType = _deprecated_typing_helper("ServiceCall")
|
||||
|
||||
# These can be removed if no deprecated constant are in this module anymore
|
||||
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
|
||||
__dir__ = partial(
|
||||
dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
|
||||
)
|
||||
__all__ = all_with_deprecated_constants(globals())
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
"""Test typing helper module."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import Context, Event, HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers import typing as ha_typing
|
||||
|
||||
from tests.common import import_and_test_deprecated_alias
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("alias_name", "replacement", "breaks_in_ha_version"),
|
||||
[
|
||||
("ContextType", Context, "2025.5"),
|
||||
("EventType", Event, "2025.5"),
|
||||
("HomeAssistantType", HomeAssistant, "2025.5"),
|
||||
("ServiceCallType", ServiceCall, "2025.5"),
|
||||
],
|
||||
)
|
||||
def test_deprecated_aliases(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
alias_name: str,
|
||||
replacement: Any,
|
||||
breaks_in_ha_version: str,
|
||||
) -> None:
|
||||
"""Test deprecated aliases."""
|
||||
import_and_test_deprecated_alias(
|
||||
caplog,
|
||||
ha_typing,
|
||||
alias_name,
|
||||
replacement,
|
||||
breaks_in_ha_version,
|
||||
)
|
||||
Reference in New Issue
Block a user