@classmethod<EOL><INDENT>def cast_item(cls, item):<DEDENT>
if not isinstance(item, cls.subtype):<EOL><INDENT>incompatible = isinstance(item, Base) and not any(<EOL>issubclass(cls.subtype, tag_type) and isinstance(item, tag_type)<EOL>for tag_type in cls.all_tags.values()<EOL>)<EOL>if incompatible:<EOL><INDENT>raise IncompatibleItemType(item, cls.subtype)<EOL><DEDENT>try:<EOL><INDENT>return cls.subtype(item)<EOL><DEDENT>except EndInstantiation:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>') from None<EOL><DEDENT>except (IncompatibleItemType, CastError):<EOL><INDENT>raise<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise CastError(item, cls.subtype) from exc<EOL><DEDENT><DEDENT>return item<EOL>
Cast list item to the appropriate tag type.