class_docstr: Inherit from this class if you wish to override any of the stages below. Otherwise, use
  ``argcomplete.autocomplete()`` directly (it's a convenience instance of this class). It has the same signature as
  :meth:`CompletionFinder.__call__()`.
docstr: Since argparse doesn't support much introspection, we monkey-patch it to replace the parse_known_args method and
  all actions with hooks that tell us which action was last taken or about to be taken, and let us have the parser
  figure out which subparsers need to be activated (then recursively monkey-patch those).
  We save all active ArgumentParsers to extract all their possible option names later.
docstr_tok: ["Since","argparse","does","n't","support","much","introspection",",","we","monkey-patch","it","to","replace","the","parse_known_args","method","and","all","actions","with","hooks","that","tell","us","which","action","was","last","taken","or","about","to","be","taken",",","and","let","us","have","the","parser","figure","out","which","subparsers","need","to","be","activated","(","then","recursively","monkey-patch","those",")",".","We","save","all","active","ArgumentParsers","to","extract","all","their","possible","option","names","later","."]
code: def _patch_argument_parser(self):
      """
      Since argparse doesn't support much introspection, we monkey-patch it to replace the parse_known_args method and
      all actions with hooks that tell us which action was last taken or about to be taken, and let us have the parser
      figure out which subparsers need to be activated (then recursively monkey-patch those).
      We save all active ArgumentParsers to extract all their possible option names later.
      """
      self.active_parsers: List[argparse.ArgumentParser] = []
      self.visited_positionals: List[argparse.Action] = []
  
      completer = self
  
      def patch(parser):
          completer.visited_positionals.append(parser)
          completer.active_parsers.append(parser)
  
          if isinstance(parser, IntrospectiveArgumentParser):
              return
  
          classname = "MonkeyPatchedIntrospectiveArgumentParser"
  
          parser.__class__ = type(
              classname,
              (IntrospectiveArgumentParser, parser.__class__),
              {},
          )
  
          for action in parser._actions:
              if hasattr(action, "_orig_class"):
                  continue
  
              # TODO: accomplish this with super
              class IntrospectAction(action.__class__):  # type: ignore
                  def __call__(
                      self,
                      parser,
                      namespace,
                      values,
                      option_string=None,
                  ):
                      debug("Action stub called on", self)
                      debug(
                          "\targs:",
                          parser,
                          namespace,
                          values,
                          option_string,
                      )
                      debug("\torig class:", self._orig_class)
                      debug("\torig callable:", self._orig_callable)
  
                      if not completer.completing:
                          self._orig_callable(
                              parser,
                              namespace,
                              values,
                              option_string=option_string,
                          )
                      elif issubclass(
                          self._orig_class, argparse._SubParsersAction
                      ):
                          debug(
                              "orig class is a subparsers action: patching and running it"
                          )
                          patch(self._name_parser_map[values[0]])
                          self._orig_callable(
                              parser,
                              namespace,
                              values,
                              option_string=option_string,
                          )
                      elif self._orig_class in safe_actions:
                          if not self.option_strings:
                              completer.visited_positionals.append(self)
  
                          self._orig_callable(
                              parser,
                              namespace,
                              values,
                              option_string=option_string,
                          )
  
              action._orig_class = action.__class__
              action._orig_callable = action.__call__
              action.__class__ = IntrospectAction
  
      patch(self._parser)
  
      debug("Active parsers:", self.active_parsers)
      debug("Visited positionals:", self.visited_positionals)
  
      return self.active_parsers
  
imports: import argparse
  import os
  import sys
  from collections.abc import Mapping
  from typing import Callable, Dict, List, Optional, Sequence, Union
  from .None import io
  from .completers import ChoicesCompleter, FilesCompleter, SuppressCompleter
  from .io import debug, mute_stderr
  from .lexers import split_line
  from .packages._argparse import IntrospectiveArgumentParser, action_is_greedy, action_is_open, action_is_satisfied
label_desc: Use image node_id 4 for calling the CompletionFinder obj's underlying member method code with example usage: obj._patch_argument_parser() and returns: self