def replace_type(items, spec, loader, found, find_embeds=True, deepen=True):<EOL>
if isinstance(items, MutableMapping):<EOL><INDENT>if items.get("<STR_LIT:type>") in ("<STR_LIT>", "<STR_LIT>") and items.get("<STR_LIT:name>"):<EOL><INDENT>if items["<STR_LIT:name>"] in found:<EOL><INDENT>return items["<STR_LIT:name>"]<EOL><DEDENT>found.add(items["<STR_LIT:name>"])<EOL><DEDENT>if not deepen:<EOL><INDENT>return items<EOL><DEDENT>items = copy.copy(items)<EOL>if not items.get("<STR_LIT:name>"):<EOL><INDENT>items["<STR_LIT:name>"] = get_anon_name(items)<EOL><DEDENT>for name in ("<STR_LIT:type>", "<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>if name in items:<EOL><INDENT>items[name] = replace_type(<EOL>items[name], spec, loader, found, find_embeds=find_embeds,<EOL>deepen=find_embeds)<EOL>if isinstance(items[name], MutableSequence):<EOL><INDENT>items[name] = flatten(items[name])<EOL><DEDENT><DEDENT><DEDENT>return items<EOL><DEDENT>if isinstance(items, MutableSequence):<EOL><INDENT>return [replace_type(i, spec, loader, found, find_embeds=find_embeds,<EOL>deepen=deepen) for i in items]<EOL><DEDENT>if isinstance(items, string_types):<EOL><INDENT>replace_with = None<EOL>if items in loader.vocab:<EOL><INDENT>items = loader.vocab[items]<EOL><DEDENT>if items in spec:<EOL><INDENT>replace_with = spec[items]<EOL><DEDENT>if replace_with:<EOL><INDENT>return replace_type(replace_with, spec, loader, found, find_embeds=find_embeds)<EOL><DEDENT>found.add(items)<EOL><DEDENT>return items<EOL>
Go through and replace types in the 'spec' mapping