code: def _patched_parse_args(
      original_parse_fn, self, args=None, namespace=None
  ):
      current_task = PatchArgumentParser._current_task
      # if we are running remotely, we always have a task id, so we better patch the argparser as soon as possible.
      if not current_task:
          from ..config import running_remotely, get_remote_task_id
  
          if running_remotely():
              # this will cause the current_task() to set PatchArgumentParser._current_task
              from clearml import Task
  
              # noinspection PyBroadException
              try:
                  current_task = Task.get_task(
                      task_id=get_remote_task_id()
                  )
                  # make sure we do not store back the values
                  # (we will do that when we actually call parse args)
                  # this will make sure that if we have args we should not track we know them
                  # noinspection PyProtectedMember
                  current_task._arguments.exclude_parser_args(
                      {"*": True}
                  )
              except Exception:
                  pass
      # automatically connect to current task:
      if current_task:
          from ..config import running_remotely
  
          if PatchArgumentParser._calling_current_task:
              # if we are here and running remotely by now we should try to parse the arguments
              parsed_args = None
              if original_parse_fn:
                  parsed_args = original_parse_fn(
                      self, args=args, namespace=namespace
                  )
                  PatchArgumentParser._add_last_parsed_args(
                      self, parsed_args
                  )
              return (
                  parsed_args
                  or PatchArgumentParser._last_parsed_args[-1]
              )
  
          PatchArgumentParser._calling_current_task = True
          # Store last instance and result
          PatchArgumentParser._add_last_arg_parser(self)
          parsed_args = parsed_args_str = None
          # parse if we are running in dev mode
          if not running_remotely() and original_parse_fn:
              parsed_args = original_parse_fn(
                  self, args=args, namespace=namespace
              )
              parsed_args_str = (
                  PatchArgumentParser._add_last_parsed_args(
                      self, parsed_args
                  )
              )
  
          # noinspection PyBroadException
          try:
              # sync to/from task
              # noinspection PyProtectedMember
              current_task._connect_argparse(
                  self,
                  args=args,
                  namespace=namespace,
                  parsed_args=parsed_args_str[0]
                  if isinstance(parsed_args_str, tuple)
                  else parsed_args_str,
              )
          except Exception:
              pass
  
          # sync back and parse
          if running_remotely():
              if original_parse_fn:
                  # if we are running python2 check if we have subparsers,
                  # if we do we need to patch the args, because there is no default subparser
                  if PY2:
                      import itertools
  
                      def _get_sub_parsers_defaults(subparser, prev=[]):
                          actions_grp = (
                              [
                                  v._actions
                                  for v 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(v, prev)
                                  for v in actions
                                  if isinstance(v, _SubParsersAction)
                                  and hasattr(v, "default")
                                  and v.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:
                              # args default to the system args
                              import sys as _sys
  
                              args = _sys.argv[1:]
                          else:
                              args = list(args)
                          # make sure we append the subparsers
                          for a in sub_parsers_defaults:
                              if a.default not in args:
                                  args.append(a.default)
  
                  parsed_args = original_parse_fn(
                      self, args=args, namespace=namespace
                  )
                  PatchArgumentParser._add_last_parsed_args(
                      self, parsed_args
                  )
              else:
                  # we should never get here
                  parsed_args = parsed_args_str or {}
                  PatchArgumentParser._add_last_parsed_args(
                      self, parsed_args
                  )
  
          PatchArgumentParser._calling_current_task = False
          return parsed_args
  
      # Store last instance and result
      PatchArgumentParser._add_last_arg_parser(self)
      parsed_args = (
          {}
          if not original_parse_fn
          else original_parse_fn(self, args=args, namespace=namespace)
      )
      PatchArgumentParser._add_last_parsed_args(self, parsed_args)
      return parsed_args
  
file_path: clearml/clearml/binding/args.py
imports: import sys
  import warnings
  from copy import copy
  from six import PY2
  from argparse import ArgumentParser, Namespace
label_desc: Use image node_id 4 for calling the PatchArgumentParser obj's underlying member method code with example usage: obj._patched_parse_args(original_parse_fn, args, namespace) and returns: parsed_args, parsed_args, unknown, list