def _check_patch_type_mismatch(self, patched_item, existing_item):
def raise_mismatch_error(patched_item, existing_item, data_type_name):<EOL><INDENT>error_msg = ('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>raise InvalidSpec(error_msg.format(<EOL>quote(patched_item.name),<EOL>quote(existing_item.name),<EOL>existing_item.path,<EOL>existing_item.lineno,<EOL>quote(data_type_name)), patched_item.lineno, patched_item.path)<EOL><DEDENT>if isinstance(patched_item, AstStructPatch):<EOL><INDENT>if not isinstance(existing_item, AstStructDef):<EOL><INDENT>raise_mismatch_error(patched_item, existing_item, '<STR_LIT>')<EOL><DEDENT><DEDENT>elif isinstance(patched_item, AstUnionPatch):<EOL><INDENT>if not isinstance(existing_item, AstUnionDef):<EOL><INDENT>raise_mismatch_error(patched_item, existing_item, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>if existing_item.closed != patched_item.closed:<EOL><INDENT>raise_mismatch_error(<EOL>patched_item, existing_item,<EOL>'<STR_LIT>' if existing_item.closed else '<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise AssertionError(<EOL>'<STR_LIT>'.format(patched_item.__class__.__name__))<EOL><DEDENT>
Enforces that each patch has a corresponding, already-defined data type.