Skip to content

Commit

Permalink
Correct line numbers in yaml node annotations (#103605)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Nov 7, 2023
1 parent 95fe7aa commit c29b0cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion homeassistant/util/yaml/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
12 changes: 6 additions & 6 deletions tests/util/yaml/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ def test_string_annotated(try_both_loaders) -> None:
"key6: 1.0\n"
)
expected_annotations = {
"key1": [("<file>", 0), ("<file>", 0)],
"key2": [("<file>", 1), ("<file>", 2)],
"key3": [("<file>", 3), ("<file>", 4)],
"key4": [("<file>", 7), (None, None)],
"key5": [("<file>", 8), (None, None)],
"key6": [("<file>", 9), (None, None)],
"key1": [("<file>", 1), ("<file>", 1)],
"key2": [("<file>", 2), ("<file>", 3)],
"key3": [("<file>", 4), ("<file>", 5)],
"key4": [("<file>", 8), (None, None)],
"key5": [("<file>", 9), (None, None)],
"key6": [("<file>", 10), (None, None)],
}
with io.StringIO(conf) as file:
doc = yaml_loader.parse_yaml(file)
Expand Down

0 comments on commit c29b0cd

Please sign in to comment.