code: def flatten_mapping(self, node):
      merge = []
      index = 0
      while index < len(node.value):
          key_node, value_node = node.value[index]
          if key_node.tag == "tag:yaml.org,2002:merge":
              del node.value[index]
              if isinstance(value_node, MappingNode):
                  self.flatten_mapping(value_node)
                  merge.extend(value_node.value)
              elif isinstance(value_node, SequenceNode):
                  submerge = []
                  for subnode in value_node.value:
                      if not isinstance(subnode, MappingNode):
                          raise ConstructorError(
                              "while constructing a mapping",
                              node.start_mark,
                              "expected a mapping for merging, but found %s"
                              % subnode.id,
                              subnode.start_mark,
                          )
                      self.flatten_mapping(subnode)
                      submerge.append(subnode.value)
                  submerge.reverse()
                  for value in submerge:
                      merge.extend(value)
              else:
                  raise ConstructorError(
                      "while constructing a mapping",
                      node.start_mark,
                      "expected a mapping or list of mappings for merging, but found %s"
                      % value_node.id,
                      value_node.start_mark,
                  )
          elif key_node.tag == "tag:yaml.org,2002:value":
              key_node.tag = "tag:yaml.org,2002:str"
              index += 1
          else:
              index += 1
      if merge:
          node.value = merge + node.value
  
imports: from .error import *
  from .nodes import *
  import collections.abc, datetime, base64, binascii, re, sys, types
label_desc: Use image node_id 2 for calling the SafeConstructor obj's underlying member method code with example usage: obj.flatten_mapping(node) without return types