Define the options in the parser (by calling a bunch of methods that express/build our desired command-line flags). Returns a tuple of: a parser object, that can parse command line arguments to mypy (expected consumer: main's process_options), a list of what flags are strict (expecte
(
program: str = "mypy",
header: str = HEADER,
stdout: TextIO = sys.stdout,
stderr: TextIO = sys.stderr,
server_options: bool = False,
)
| 490 | |
| 491 | |
| 492 | def define_options( |
| 493 | program: str = "mypy", |
| 494 | header: str = HEADER, |
| 495 | stdout: TextIO = sys.stdout, |
| 496 | stderr: TextIO = sys.stderr, |
| 497 | server_options: bool = False, |
| 498 | ) -> tuple[CapturableArgumentParser, list[str], list[tuple[str, bool]]]: |
| 499 | """Define the options in the parser (by calling a bunch of methods that express/build our desired command-line flags). |
| 500 | Returns a tuple of: |
| 501 | a parser object, that can parse command line arguments to mypy (expected consumer: main's process_options), |
| 502 | a list of what flags are strict (expected consumer: docs' html_builder's _add_strict_list), |
| 503 | strict_flag_assignments (expected consumer: main's process_options).""" |
| 504 | parser = CapturableArgumentParser( |
| 505 | prog=program, |
| 506 | usage=header, |
| 507 | description=DESCRIPTION, |
| 508 | epilog=FOOTER, |
| 509 | fromfile_prefix_chars="@", |
| 510 | formatter_class=AugmentedHelpFormatter, |
| 511 | add_help=False, |
| 512 | stdout=stdout, |
| 513 | stderr=stderr, |
| 514 | ) |
| 515 | |
| 516 | strict_flag_names: list[str] = [] |
| 517 | strict_flag_assignments: list[tuple[str, bool]] = [] |
| 518 | |
| 519 | def add_invertible_flag( |
| 520 | flag: str, |
| 521 | *, |
| 522 | inverse: str | None = None, |
| 523 | default: bool, |
| 524 | dest: str | None = None, |
| 525 | help: str, |
| 526 | strict_flag: bool = False, |
| 527 | group: argparse._ActionsContainer | None = None, |
| 528 | ) -> None: |
| 529 | if inverse is None: |
| 530 | inverse = invert_flag_name(flag) |
| 531 | if group is None: |
| 532 | group = parser |
| 533 | |
| 534 | if help is not argparse.SUPPRESS: |
| 535 | help += f" (inverse: {inverse})" |
| 536 | |
| 537 | arg = group.add_argument( |
| 538 | flag, action="store_false" if default else "store_true", dest=dest, help=help |
| 539 | ) |
| 540 | dest = arg.dest |
| 541 | group.add_argument( |
| 542 | inverse, |
| 543 | action="store_true" if default else "store_false", |
| 544 | dest=dest, |
| 545 | help=argparse.SUPPRESS, |
| 546 | ) |
| 547 | if strict_flag: |
| 548 | assert dest is not None |
| 549 | strict_flag_names.append(flag) |
no test coverage detected
searching dependent graphs…