Remove deprecated YAML loaders (#130364)

This commit is contained in:
epenet 2024-11-11 20:24:51 +01:00 committed by GitHub
parent ebe62501d6
commit 313309a7e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 88 deletions

View File

@ -25,7 +25,6 @@ except ImportError:
from propcache import cached_property
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.frame import report
from .const import SECRET_YAML
from .objects import Input, NodeDictClass, NodeListClass, NodeStrClass
@ -144,37 +143,6 @@ class FastSafeLoader(FastestAvailableSafeLoader, _LoaderMixin):
self.secrets = secrets
class SafeLoader(FastSafeLoader):
"""Provided for backwards compatibility. Logs when instantiated."""
def __init__(*args: Any, **kwargs: Any) -> None:
"""Log a warning and call super."""
SafeLoader.__report_deprecated()
FastSafeLoader.__init__(*args, **kwargs)
@classmethod
def add_constructor(cls, tag: str, constructor: Callable) -> None:
"""Log a warning and call super."""
SafeLoader.__report_deprecated()
FastSafeLoader.add_constructor(tag, constructor)
@classmethod
def add_multi_constructor(
cls, tag_prefix: str, multi_constructor: Callable
) -> None:
"""Log a warning and call super."""
SafeLoader.__report_deprecated()
FastSafeLoader.add_multi_constructor(tag_prefix, multi_constructor)
@staticmethod
def __report_deprecated() -> None:
"""Log deprecation warning."""
report(
"uses deprecated 'SafeLoader' instead of 'FastSafeLoader', "
"which will stop working in HA Core 2024.6,"
)
class PythonSafeLoader(yaml.SafeLoader, _LoaderMixin):
"""Python safe loader."""
@ -184,37 +152,6 @@ class PythonSafeLoader(yaml.SafeLoader, _LoaderMixin):
self.secrets = secrets
class SafeLineLoader(PythonSafeLoader):
"""Provided for backwards compatibility. Logs when instantiated."""
def __init__(*args: Any, **kwargs: Any) -> None:
"""Log a warning and call super."""
SafeLineLoader.__report_deprecated()
PythonSafeLoader.__init__(*args, **kwargs)
@classmethod
def add_constructor(cls, tag: str, constructor: Callable) -> None:
"""Log a warning and call super."""
SafeLineLoader.__report_deprecated()
PythonSafeLoader.add_constructor(tag, constructor)
@classmethod
def add_multi_constructor(
cls, tag_prefix: str, multi_constructor: Callable
) -> None:
"""Log a warning and call super."""
SafeLineLoader.__report_deprecated()
PythonSafeLoader.add_multi_constructor(tag_prefix, multi_constructor)
@staticmethod
def __report_deprecated() -> None:
"""Log deprecation warning."""
report(
"uses deprecated 'SafeLineLoader' instead of 'PythonSafeLoader', "
"which will stop working in HA Core 2024.6,"
)
type LoaderType = FastSafeLoader | PythonSafeLoader

View File

@ -494,31 +494,6 @@ def mock_integration_frame() -> Generator[Mock]:
yield correct_frame
@pytest.mark.parametrize(
("loader_class", "message"),
[
(yaml.loader.SafeLoader, "'SafeLoader' instead of 'FastSafeLoader'"),
(
yaml.loader.SafeLineLoader,
"'SafeLineLoader' instead of 'PythonSafeLoader'",
),
],
)
@pytest.mark.usefixtures("mock_integration_frame")
async def test_deprecated_loaders(
caplog: pytest.LogCaptureFixture,
loader_class: type,
message: str,
) -> None:
"""Test instantiating the deprecated yaml loaders logs a warning."""
with (
pytest.raises(TypeError),
patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()),
):
loader_class()
assert (f"Detected that integration 'hue' uses deprecated {message}") in caplog.text
@pytest.mark.usefixtures("try_both_loaders")
def test_string_annotated() -> None:
"""Test strings are annotated with file + line."""