Skip to content

Commit 03e8f78

Browse files
committed
Move task_to_str to Task class
Partial: #4548
1 parent 17d2029 commit 03e8f78

File tree

3 files changed

+2
-33
lines changed

3 files changed

+2
-33
lines changed

src/ansiblelint/rules/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _enrich_matcherror_with_task_details(
108108
) -> None:
109109
match.task = task
110110
if not match.details:
111-
match.details = "Task/Handler: " + ansiblelint.utils.task_to_str(task)
111+
match.details = "Task/Handler: " + str(task)
112112

113113
match.lineno = max(match.lineno, task[LINE_NUMBER_KEY])
114114

src/ansiblelint/utils.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -712,37 +712,6 @@ def normalize_task_v2(task: Task) -> dict[str, Any]:
712712
return result
713713

714714

715-
def task_to_str(task: dict[str, Any]) -> str:
716-
"""Make a string identifier for the given task."""
717-
name = task.get("name")
718-
if name:
719-
return str(name)
720-
action = task.get("action")
721-
if isinstance(action, str) or not isinstance(action, dict):
722-
return str(action)
723-
args = [
724-
f"{k}={v}"
725-
for (k, v) in action.items()
726-
if k
727-
not in [
728-
"__ansible_module__",
729-
"__ansible_module_original__",
730-
"_raw_params",
731-
LINE_NUMBER_KEY,
732-
FILENAME_KEY,
733-
]
734-
]
735-
736-
raw_params = action.get("_raw_params", [])
737-
if isinstance(raw_params, list):
738-
for item in raw_params:
739-
args.extend(str(item))
740-
else:
741-
args.append(raw_params)
742-
743-
return f"{action['__ansible_module__']} {' '.join(args)}"
744-
745-
746715
# pylint: disable=too-many-nested-blocks
747716
def extract_from_list( # type: ignore[no-any-unimported]
748717
blocks: AnsibleBaseYAMLObject,

test/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def test_template(template: str, output: str) -> None:
281281
def test_task_to_str_unicode() -> None:
282282
"""Ensure that extracting messages from tasks preserves Unicode."""
283283
task = utils.Task({"fail": {"msg": "unicode é ô à"}}, filename="filename.yml")
284-
result = utils.task_to_str(task._normalize_task()) # noqa: SLF001
284+
result = str(utils.Task(task._normalize_task())) # noqa: SLF001
285285
assert result == "fail msg=unicode é ô à"
286286

287287

0 commit comments

Comments
 (0)