From c29b0cd05b70c2b5c13b71f4378c15a210273b25 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 7 Nov 2023 23:22:23 +0100 Subject: [PATCH] Correct line numbers in yaml node annotations (#103605) --- homeassistant/util/yaml/loader.py | 2 +- tests/util/yaml/test_init.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/homeassistant/util/yaml/loader.py b/homeassistant/util/yaml/loader.py index 75942e5ea79..73e7861902f 100644 --- a/homeassistant/util/yaml/loader.py +++ b/homeassistant/util/yaml/loader.py @@ -240,7 +240,7 @@ def _add_reference( # type: ignore[no-untyped-def] if isinstance(obj, str): obj = NodeStrClass(obj) setattr(obj, "__config_file__", loader.get_name()) - setattr(obj, "__line__", node.start_mark.line) + setattr(obj, "__line__", node.start_mark.line + 1) return obj diff --git a/tests/util/yaml/test_init.py b/tests/util/yaml/test_init.py index 53b3143ac0b..315f6618e89 100644 --- a/tests/util/yaml/test_init.py +++ b/tests/util/yaml/test_init.py @@ -564,12 +564,12 @@ def test_string_annotated(try_both_loaders) -> None: "key6: 1.0\n" ) expected_annotations = { - "key1": [("", 0), ("", 0)], - "key2": [("", 1), ("", 2)], - "key3": [("", 3), ("", 4)], - "key4": [("", 7), (None, None)], - "key5": [("", 8), (None, None)], - "key6": [("", 9), (None, None)], + "key1": [("", 1), ("", 1)], + "key2": [("", 2), ("", 3)], + "key3": [("", 4), ("", 5)], + "key4": [("", 8), (None, None)], + "key5": [("", 9), (None, None)], + "key6": [("", 10), (None, None)], } with io.StringIO(conf) as file: doc = yaml_loader.parse_yaml(file)