@staticmethod
def _patched_parse_args(original_parse_fn, self, args=None, namespace=None):
    current_task = PatchArgumentParser._current_task
    if (not current_task):
        from ..config import running_remotely, get_remote_task_id
        if running_remotely():
            from trains import Task
            try:
                current_task = Task.get_task(task_id=get_remote_task_id())
            except Exception:
                pass
    if current_task:
        from ..config import running_remotely
        if PatchArgumentParser._calling_current_task:
            if original_parse_fn:
                PatchArgumentParser._add_last_parsed_args(original_parse_fn(self, args=args, namespace=namespace))
            return PatchArgumentParser._last_parsed_args[(- 1)]
        PatchArgumentParser._calling_current_task = True
        PatchArgumentParser._add_last_arg_parser(self)
        parsed_args = None
        if ((not running_remotely()) and original_parse_fn):
            parsed_args = original_parse_fn(self, args=args, namespace=namespace)
            PatchArgumentParser._add_last_parsed_args(parsed_args)
        try:
            current_task._connect_argparse(self, args=args, namespace=namespace, parsed_args=(parsed_args[0] if isinstance(parsed_args, tuple) else parsed_args))
        except Exception:
            pass
        if (running_remotely() and original_parse_fn):
            if PY2:
                import itertools

                def _get_sub_parsers_defaults(subparser, prev=[]):
                    actions_grp = ([a._actions for a in subparser.choices.values()] if isinstance(subparser, _SubParsersAction) else [subparser._actions])
                    sub_parsers_defaults = ([[subparser]] if (hasattr(subparser, 'default') and subparser.default) else [])
                    for actions in actions_grp:
                        sub_parsers_defaults += [_get_sub_parsers_defaults(a, prev) for a in actions if (isinstance(a, _SubParsersAction) and hasattr(a, 'default') and a.default)]
                    return list(itertools.chain.from_iterable(sub_parsers_defaults))
                sub_parsers_defaults = _get_sub_parsers_defaults(self)
                if sub_parsers_defaults:
                    if (args is None):
                        import sys as _sys
                        args = _sys.argv[1:]
                    else:
                        args = list(args)
                    for a in sub_parsers_defaults:
                        if (a.default not in args):
                            args.append(a.default)
            PatchArgumentParser._add_last_parsed_args(original_parse_fn(self, args=args, namespace=namespace))
        else:
            PatchArgumentParser._add_last_parsed_args((parsed_args or {}))
        PatchArgumentParser._calling_current_task = False
        return PatchArgumentParser._last_parsed_args[(- 1)]
    PatchArgumentParser._add_last_arg_parser(self)
    PatchArgumentParser._add_last_parsed_args(({} if (not original_parse_fn) else original_parse_fn(self, args=args, namespace=namespace)))
    return PatchArgumentParser._last_parsed_args[(- 1)]
@staticmethod
def _patched_parse_args(original_parse_fn, self, args=None, namespace=None):
    current_task = PatchArgumentParser._current_task
    if (not current_task):
        from ..config import running_remotely, get_remote_task_id
        if running_remotely():
            from trains import Task
            try:
                current_task = Task.get_task(task_id=get_remote_task_id())
            except Exception:
                pass
    if current_task:
        from ..config import running_remotely
        if PatchArgumentParser._calling_current_task:
            if original_parse_fn:
                PatchArgumentParser._add_last_parsed_args(original_parse_fn(self, args=args, namespace=namespace))
            return PatchArgumentParser._last_parsed_args[(- 1)]
        PatchArgumentParser._calling_current_task = True
        PatchArgumentParser._add_last_arg_parser(self)
        parsed_args = None
        if ((not running_remotely()) and original_parse_fn):
            parsed_args = original_parse_fn(self, args=args, namespace=namespace)
            PatchArgumentParser._add_last_parsed_args(parsed_args)
        try:
            current_task._connect_argparse(self, args=args, namespace=namespace, parsed_args=(parsed_args[0] if isinstance(parsed_args, tuple) else parsed_args))
        except Exception:
            pass
        if (running_remotely() and original_parse_fn):
            if PY2:
                import itertools

                def _get_sub_parsers_defaults(subparser, prev=[]):
                    actions_grp = ([a._actions for a in subparser.choices.values()] if isinstance(subparser, _SubParsersAction) else [subparser._actions])
                    sub_parsers_defaults = ([[subparser]] if (hasattr(subparser, 'default') and subparser.default) else [])
                    for actions in actions_grp:
                        sub_parsers_defaults += [_get_sub_parsers_defaults(a, prev) for a in actions if (isinstance(a, _SubParsersAction) and hasattr(a, 'default') and a.default)]
                    return list(itertools.chain.from_iterable(sub_parsers_defaults))
                sub_parsers_defaults = _get_sub_parsers_defaults(self)
                if sub_parsers_defaults:
                    if (args is None):
                        import sys as _sys
                        args = _sys.argv[1:]
                    else:
                        args = list(args)
                    for a in sub_parsers_defaults:
                        if (a.default not in args):
                            args.append(a.default)
            PatchArgumentParser._add_last_parsed_args(original_parse_fn(self, args=args, namespace=namespace))
        else:
            PatchArgumentParser._add_last_parsed_args((parsed_args or {}))
        PatchArgumentParser._calling_current_task = False
        return PatchArgumentParser._last_parsed_args[(- 1)]
    PatchArgumentParser._add_last_arg_parser(self)
    PatchArgumentParser._add_last_parsed_args(({} if (not original_parse_fn) else original_parse_fn(self, args=args, namespace=namespace)))
    return PatchArgumentParser._last_parsed_args[(- 1)]