diff --git a/homeassistant/util/json.py b/homeassistant/util/json.py index 1479550b615..fa67f6b1dcc 100644 --- a/homeassistant/util/json.py +++ b/homeassistant/util/json.py @@ -2,8 +2,6 @@ from __future__ import annotations -from collections.abc import Callable -import json import logging from os import PathLike from typing import Any @@ -12,8 +10,6 @@ import orjson from homeassistant.exceptions import HomeAssistantError -from .file import WriteError # noqa: F401 - _SENTINEL = object() _LOGGER = logging.getLogger(__name__) @@ -129,63 +125,9 @@ def load_json_object( raise HomeAssistantError(f"Expected JSON to be parsed as a dict got {type(value)}") -def save_json( - filename: str, - data: list | dict, - private: bool = False, - *, - encoder: type[json.JSONEncoder] | None = None, - atomic_writes: bool = False, -) -> None: - """Save JSON data to a file.""" - # pylint: disable-next=import-outside-toplevel - from homeassistant.helpers.frame import report - - report( - ( - "uses save_json from homeassistant.util.json module." - " This is deprecated and will stop working in Home Assistant 2022.4, it" - " should be updated to use homeassistant.helpers.json module instead" - ), - error_if_core=False, - ) - - # pylint: disable-next=import-outside-toplevel - import homeassistant.helpers.json as json_helper - - json_helper.save_json( - filename, data, private, encoder=encoder, atomic_writes=atomic_writes - ) - - def format_unserializable_data(data: dict[str, Any]) -> str: """Format output of find_paths in a friendly way. Format is comma separated: =() """ return ", ".join(f"{path}={value}({type(value)}" for path, value in data.items()) - - -def find_paths_unserializable_data( - bad_data: Any, *, dump: Callable[[Any], str] = json.dumps -) -> dict[str, Any]: - """Find the paths to unserializable data. - - This method is slow! Only use for error handling. - """ - # pylint: disable-next=import-outside-toplevel - from homeassistant.helpers.frame import report - - report( - ( - "uses find_paths_unserializable_data from homeassistant.util.json module." - " This is deprecated and will stop working in Home Assistant 2022.4, it" - " should be updated to use homeassistant.helpers.json module instead" - ), - error_if_core=False, - ) - - # pylint: disable-next=import-outside-toplevel - import homeassistant.helpers.json as json_helper - - return json_helper.find_paths_unserializable_data(bad_data, dump=dump) diff --git a/pylint/plugins/hass_imports.py b/pylint/plugins/hass_imports.py index 3ec8b6c3cd9..57b71560b53 100644 --- a/pylint/plugins/hass_imports.py +++ b/pylint/plugins/hass_imports.py @@ -392,12 +392,6 @@ _OBSOLETE_IMPORT: dict[str, list[ObsoleteImportMatch]] = { constant=re.compile(r"^IMPERIAL_SYSTEM$"), ), ], - "homeassistant.util.json": [ - ObsoleteImportMatch( - reason="moved to homeassistant.helpers.json", - constant=re.compile(r"^save_json|find_paths_unserializable_data$"), - ), - ], } diff --git a/tests/util/test_json.py b/tests/util/test_json.py index 3a314bb5a1b..05dab46002d 100644 --- a/tests/util/test_json.py +++ b/tests/util/test_json.py @@ -131,34 +131,6 @@ def test_json_loads_object() -> None: json_loads_object("null") -async def test_deprecated_test_find_unserializable_data( - caplog: pytest.LogCaptureFixture, -) -> None: - """Test deprecated test_find_unserializable_data logs a warning.""" - # pylint: disable-next=hass-deprecated-import,import-outside-toplevel - from homeassistant.util.json import find_paths_unserializable_data - - find_paths_unserializable_data(1) - assert ( - "uses find_paths_unserializable_data from homeassistant.util.json" - in caplog.text - ) - assert "should be updated to use homeassistant.helpers.json module" in caplog.text - - -async def test_deprecated_save_json( - caplog: pytest.LogCaptureFixture, tmp_path: Path -) -> None: - """Test deprecated save_json logs a warning.""" - # pylint: disable-next=hass-deprecated-import,import-outside-toplevel - from homeassistant.util.json import save_json - - fname = tmp_path / "test1.json" - save_json(fname, TEST_JSON_A) - assert "uses save_json from homeassistant.util.json" in caplog.text - assert "should be updated to use homeassistant.helpers.json module" in caplog.text - - async def test_loading_derived_class() -> None: """Test loading data from classes derived from str."""