Skip to content

Commit dcd5788

Browse files
mypy fixes
1 parent 6ca8fa6 commit dcd5788

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/layered_config_tree/utilities.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
"""
1010

11+
from collections.abc import Hashable
1112
from pathlib import Path
1213
from typing import Any
1314

@@ -59,7 +60,9 @@ def load_yaml(data: str | Path) -> dict[str, Any]:
5960
class SafeLoader(yaml.SafeLoader):
6061
"""A yaml.SafeLoader that restricts duplicate keys."""
6162

62-
def construct_mapping(self, node, deep=False):
63+
def construct_mapping(
64+
self, node: yaml.MappingNode, deep: bool = False
65+
) -> dict[Hashable, Any]:
6366
"""Constructs the standard mapping after checking for duplicates.
6467
6568
Raises
@@ -79,7 +82,7 @@ def construct_mapping(self, node, deep=False):
7982
"""
8083
mapping = []
8184
for key_node, _value_node in node.value:
82-
key = self.construct_object(key_node, deep=deep)
85+
key = self.construct_object(key_node, deep=deep) # type: ignore[no-untyped-call]
8386
if key in mapping:
8487
raise DuplicatedConfigurationError(
8588
f"Duplicate key detected at same level of YAML: {key}. Resolve duplicates and try again.",

tests/test_ingestion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def test_load_yaml_file(tmp_path: Path, path_type: type[str | Path]) -> None:
6363
def test_load_yaml_duplicates_raise(
6464
duplicates: bool, load_from_file: bool, tmp_path: Path
6565
) -> None:
66-
test_yaml = TEST_YAML_DUPLICATE_KEYS if duplicates else TEST_YAML_ONE
66+
test_str: str = TEST_YAML_DUPLICATE_KEYS if duplicates else TEST_YAML_ONE
6767
if load_from_file:
6868
tmp_file = tmp_path / "test_dupliate_keys.yaml"
69-
tmp_file.write_text(test_yaml)
70-
test_yaml = tmp_file
69+
tmp_file.write_text(test_str)
70+
test_yaml = tmp_file if load_from_file else test_str
7171

7272
lct = LayeredConfigTree()
7373

0 commit comments

Comments
 (0)