def build_parser_for_fileobject_and_desiredtype(self, obj_on_filesystem: PersistedObject, object_type: Type[T],<EOL>logger: Logger = None) -> Tuple[Type, Parser]:
<EOL>object_types = get_alternate_types_resolving_forwardref_union_and_typevar(object_type)<EOL>if len(object_types) == <NUM_LIT:1>:<EOL><INDENT>parsers = self._build_parser_for_fileobject_and_desiredtype(obj_on_filesystem, object_typ=object_types[<NUM_LIT:0>],<EOL>logger=logger)<EOL>if len(parsers) > <NUM_LIT:1>:<EOL><INDENT>return object_types[<NUM_LIT:0>], CascadingParser(parsers)<EOL><DEDENT>else:<EOL><INDENT>return next(iter(parsers.items()))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>parsers = OrderedDict()<EOL>errors = OrderedDict()<EOL>for typ in object_types:<EOL><INDENT>try:<EOL><INDENT>parsers.update(self._build_parser_for_fileobject_and_desiredtype(obj_on_filesystem, object_typ=typ,<EOL>logger=logger))<EOL><DEDENT>except NoParserFoundForObjectExt as e:<EOL><INDENT>logger.warning("<STR_LIT>".format(type(e).__name__, e))<EOL>errors[e] = e<EOL><DEDENT>except NoParserFoundForObjectType as f:<EOL><INDENT>logger.warning("<STR_LIT>".format(type(f).__name__, f))<EOL>errors[f] = f<EOL><DEDENT><DEDENT>if len(parsers) > <NUM_LIT:0>:<EOL><INDENT>return object_type, CascadingParser(parsers)<EOL><DEDENT>else:<EOL><INDENT>raise NoParserFoundForUnionType.create(obj_on_filesystem, object_type, errors)<EOL><DEDENT><DEDENT>
Builds from the registry, a parser to parse object obj_on_filesystem as an object of type object_type.

To do that, it iterates through all registered parsers in the list in reverse order (last inserted first),
and checks if they support the provided object format (single or multifile) and type.
If several parsers match, it returns a cascadingparser that will try them in order.

If several alternatives are requested (through a root Union type), this is done independently for each
alternative.

:param obj_on_filesystem:
:param object_type:
:param logger:
:return: a type to use and a parser. The type to use is either directly the one provided, or a resolved one in
case of TypeVar