Repository: google/python-fire
File: fire/core.py (Python)

Code before:
          # Since there's no next arg or the next arg is a Flag, we consider
          # this flag to be a boolean.
          got_argument = True
          if keyword in fn_args:
            value = 'True'
          elif keyword.startswith('no'):
            keyword = keyword[2:]
            value = 'False'
          else:
            value = 'True'
        else:
          if index + 1 < len(args):
            value = args[index + 1]
            got_argument = True

        keyword = keyword.replace('-', '_')

        # In order for us to consume the argument as a keyword arg, we either:
        # Need to be explicitly expecting the keyword, or we need to be
        # accepting **kwargs.
        if got_argument and (keyword in fn_args or fn_keywords):
          kwargs[keyword] = value
          skip_argument = not contains_equals and not is_bool_syntax
        else:
          unconsumed_named_args.append(argument)
        arg_consumed = True

      if not arg_consumed:
        # The argument was not consumed, so it is still a remaining argument.
        remaining_args.append(argument)
  else:
    remaining_args = args

  return kwargs, unconsumed_named_args, remaining_args


def _ParseValue(value, index, arg, metadata):
  """Parses value, a string, into the appropriate type.

  The function used to parse value is determined by the remaining arguments.

  Args:
    value: The string value to be parsed, typically a command line argument.
    index: The index of the value in the function's argspec.
    arg: The name of the argument the value is being parsed for.
    metadata: Metadata about the function, typically from Fire decorators.
  Returns:
    value, parsed into the appropriate type for calling a function.
  """
  parse_fn = parser.DefaultParseValue


Review comment (suggestion):
We can remove `arg_consumed` altogether (here and at 698), and replace the if at 739 with an `else`.

Code after:
          (index + 1 == len(args) or args[index + 1].startswith('--')))
      if contains_equals:
        keyword, value = keyword.split('=', 1)
        got_argument = True
      elif is_bool_syntax:
        # Since there's no next arg or the next arg is a Flag, we consider
        # this flag to be a boolean.
        got_argument = True
        if keyword in fn_args:
          value = 'True'
        elif keyword.startswith('no'):
          keyword = keyword[2:]
          value = 'False'
        else:
          value = 'True'
      else:
        if index + 1 < len(args):
          value = args[index + 1]
          got_argument = True

      keyword = keyword.replace('-', '_')

      # In order for us to consume the argument as a keyword arg, we either:
      # Need to be explicitly expecting the keyword, or we need to be
      # accepting **kwargs.
      if got_argument:
        skip_argument = not contains_equals and not is_bool_syntax
        arg_consumed = True
        if keyword in fn_args or fn_keywords:
          kwargs[keyword] = value
        else:
          remaining_kwargs.append(argument)
          if skip_argument:
            remaining_kwargs.append(args[index + 1])

    if not arg_consumed:
      # The argument was not consumed, so it is still a remaining argument.
      remaining_args.append(argument)

  return kwargs, remaining_kwargs, remaining_args


def _ParseValue(value, index, arg, metadata):
  """Parses value, a string, into the appropriate type.

  The function used to parse value is determined by the remaining arguments.

  Args:
    value: The string value to be parsed, typically a command line argument.
    index: The index of the value in the function's argspec.
    arg: The name of the argument the value is being parsed for.