def _get_type_or_substitute(typecode, pyobj, sw, elt):
sub = getattr(pyobj, '<STR_LIT>', typecode)<EOL>if sub is typecode or sub is None:<EOL><INDENT>return typecode<EOL><DEDENT>if isinstance(typecode, AnyElement):<EOL><INDENT>return sub<EOL><DEDENT>if isinstance(sub, ElementDeclaration):<EOL><INDENT>if (typecode.nspname,typecode.pname) == (sub.nspname,sub.pname):<EOL><INDENT>raise TypeError('<STR_LIT>' %<EOL>(typecode.nspname, typecode.pname, sw.Backtrace(elt),))<EOL><DEDENT>if _is_substitute_element(typecode, sub):<EOL><INDENT>return sub<EOL><DEDENT>raise TypeError('<STR_LIT>' %<EOL>(typecode.nspname, typecode.pname, sub.nspname, sub.pname,<EOL>sw.Backtrace(elt),))<EOL><DEDENT>if not isinstance(typecode, AnyType) and not isinstance(sub, typecode.__class__):<EOL><INDENT>raise TypeError('<STR_LIT>' %<EOL>(sub, typecode, sw.Backtrace(elt),))<EOL><DEDENT>sub = _copy(sub)<EOL>sub.nspname = typecode.nspname<EOL>sub.pname = typecode.pname<EOL>sub.aname = typecode.aname<EOL>sub.minOccurs = sub.maxOccurs = <NUM_LIT:1><EOL>return sub<EOL>
return typecode or substitute type for wildcard or
    derived type.  For serialization only.