If you want the bootloader to throw an error, you just need to define your own bootloader using a constructor that checks if the key is in the ยน mapping:
import collections import ruamel.yaml as yaml from ruamel.yaml.reader import Reader from ruamel.yaml.scanner import Scanner from ruamel.yaml.parser_ import Parser from ruamel.yaml.composer import Composer from ruamel.yaml.constructor import Constructor from ruamel.yaml.resolver import Resolver from ruamel.yaml.nodes import MappingNode from ruamel.yaml.compat import PY2, PY3 class MyConstructor(Constructor): def construct_mapping(self, node, deep=False): if not isinstance(node, MappingNode): raise ConstructorError( None, None, "expected a mapping node, but found %s" % node.id, node.start_mark) mapping = {} for key_node, value_node in node.value:
and this raises a KeyError .
Note that the curly braces used in your example are not needed.
I'm not sure if this will work with key merging .
ยน This was done using ruamel.yaml , of which I am the author. ruamel.yaml extended version of PyYAML, and the loader code for the latter should be similar.
source share