MCPcopy
hub / github.com/google/python-fire / _consume_line

Function _consume_line

fire/docstrings.py:411–507  ·  view source on GitHub ↗

Consumes one line of text, updating the state accordingly. When _consume_line is called, part of the line may already have been processed for header information. Args: line_info: Information about the current and next line of the docstring. state: The state of the docstring parser.

(line_info, state)

Source from the content-addressed store, hash-verified

409
410
411def _consume_line(line_info, state):
412 """Consumes one line of text, updating the state accordingly.
413
414 When _consume_line is called, part of the line may already have been processed
415 for header information.
416
417 Args:
418 line_info: Information about the current and next line of the docstring.
419 state: The state of the docstring parser.
420 """
421 _update_section_state(line_info, state)
422
423 if state.section.title is None:
424 if state.summary.permitted:
425 if line_info.remaining:
426 state.summary.lines.append(line_info.remaining)
427 elif state.summary.lines:
428 state.summary.permitted = False
429 else:
430 # We're past the end of the summary.
431 # Additions now contribute to the description.
432 state.description.lines.append(line_info.remaining_raw)
433 else:
434 state.summary.permitted = False
435
436 if state.section.new and state.section.format == Formats.RST:
437 # The current line starts with an RST directive, e.g. ":param arg:".
438 directive = _get_directive(line_info)
439 directive_tokens = directive.split()
440 if state.section.title == Sections.ARGS:
441 name = directive_tokens[-1]
442 arg = _get_or_create_arg_by_name(
443 state,
444 name,
445 is_kwarg=directive_tokens[0] == 'key'
446 )
447 if len(directive_tokens) == 3:
448 # A param directive of the form ":param type arg:".
449 arg.type.lines.append(directive_tokens[1])
450 state.current_arg = arg
451 elif state.section.title == Sections.TYPE:
452 name = directive_tokens[-1]
453 arg = _get_or_create_arg_by_name(state, name)
454 state.current_arg = arg
455
456 if (state.section.format == Formats.NUMPY and
457 _line_is_hyphens(line_info.remaining)):
458 # Skip this all-hyphens line, which is part of the numpy section header.
459 return
460
461 if state.section.title == Sections.ARGS:
462 if state.section.format == Formats.GOOGLE:
463 _consume_google_args_line(line_info, state)
464 elif state.section.format == Formats.RST:
465 state.current_arg.description.lines.append(line_info.remaining.strip())
466 elif state.section.format == Formats.NUMPY:
467 line_stripped = line_info.remaining.strip()
468 if _is_arg_name(line_stripped):

Callers 1

parseFunction · 0.85

Calls 8

_update_section_stateFunction · 0.85
_get_directiveFunction · 0.85
_line_is_hyphensFunction · 0.85
_is_arg_nameFunction · 0.85
_as_arg_namesFunction · 0.85

Tested by

no test coverage detected