mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Remove deprecated YAML loaders (#130364)
This commit is contained in:
parent
ebe62501d6
commit
313309a7e0
@ -25,7 +25,6 @@ except ImportError:
|
|||||||
from propcache import cached_property
|
from propcache import cached_property
|
||||||
|
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.frame import report
|
|
||||||
|
|
||||||
from .const import SECRET_YAML
|
from .const import SECRET_YAML
|
||||||
from .objects import Input, NodeDictClass, NodeListClass, NodeStrClass
|
from .objects import Input, NodeDictClass, NodeListClass, NodeStrClass
|
||||||
@ -144,37 +143,6 @@ class FastSafeLoader(FastestAvailableSafeLoader, _LoaderMixin):
|
|||||||
self.secrets = secrets
|
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):
|
class PythonSafeLoader(yaml.SafeLoader, _LoaderMixin):
|
||||||
"""Python safe loader."""
|
"""Python safe loader."""
|
||||||
|
|
||||||
@ -184,37 +152,6 @@ class PythonSafeLoader(yaml.SafeLoader, _LoaderMixin):
|
|||||||
self.secrets = secrets
|
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
|
type LoaderType = FastSafeLoader | PythonSafeLoader
|
||||||
|
|
||||||
|
|
||||||
|
@ -494,31 +494,6 @@ def mock_integration_frame() -> Generator[Mock]:
|
|||||||
yield correct_frame
|
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")
|
@pytest.mark.usefixtures("try_both_loaders")
|
||||||
def test_string_annotated() -> None:
|
def test_string_annotated() -> None:
|
||||||
"""Test strings are annotated with file + line."""
|
"""Test strings are annotated with file + line."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user