Skip to content

Commit

Permalink
Remove deprecated nested_items
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Mar 4, 2023
1 parent b80a220 commit 57cc8e0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 43 deletions.
26 changes: 1 addition & 25 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import logging
import os
import re
import warnings
from argparse import Namespace
from collections.abc import Generator, ItemsView, Mapping, Sequence
from collections.abc import ItemsView, Mapping, Sequence
from functools import lru_cache
from pathlib import Path
from typing import Any, Callable
Expand Down Expand Up @@ -878,26 +877,3 @@ def _extend_with_roles(lintables: list[Lintable]) -> None:
def convert_to_boolean(value: Any) -> bool:
"""Use Ansible to convert something to a boolean."""
return bool(boolean(value))


def nested_items(
data: dict[Any, Any] | list[Any], parent: str = ""
) -> Generator[tuple[Any, Any, str], None, None]:
"""Iterate a nested data structure."""
warnings.warn(
"Call to deprecated function ansiblelint.utils.nested_items. "
"Use ansiblelint.yaml_utils.nested_items_path instead.",
category=DeprecationWarning,
stacklevel=2,
)
if isinstance(data, dict):
for k, v in data.items():
yield k, v, parent
# pylint: disable=redefined-outer-name
for k, v, returned_parent in nested_items(v, k):
yield k, v, returned_parent
if isinstance(data, list):
for item in data:
yield "list-item", item, parent
for k, v, returned_parent in nested_items(item):
yield k, v, returned_parent
18 changes: 0 additions & 18 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,24 +376,6 @@ def test_get_rules_dirs_with_custom_rules(
assert get_rules_dirs(user_ruledirs, use_default) == expected


def test_nested_items() -> None:
"""Verify correct function of nested_items()."""
data = {"foo": "text", "bar": {"some": "text2"}, "fruits": ["apple", "orange"]}

items = [
("foo", "text", ""),
("bar", {"some": "text2"}, ""),
("some", "text2", "bar"),
("fruits", ["apple", "orange"], ""),
("list-item", "apple", "fruits"),
("list-item", "orange", "fruits"),
]
with pytest.deprecated_call(
match=r"Call to deprecated function ansiblelint\.utils\.nested_items.*"
):
assert list(utils.nested_items(data)) == items


def test_find_children() -> None:
"""Verify correct function of find_children()."""
utils.find_children(Lintable("examples/playbooks/find_children.yml"))
Expand Down

0 comments on commit 57cc8e0

Please sign in to comment.