MCPcopy
hub / github.com/python/mypy / process_options

Function process_options

mypy/main.py:1408–1629  ·  view source on GitHub ↗

Parse command line arguments. If a FileSystemCache is passed in, and package_root options are given, call fscache.set_package_root() to set the cache's package root. Returns a tuple of: a list of source files, an Options collected from flags.

(
    args: list[str],
    stdout: TextIO | None = None,
    stderr: TextIO | None = None,
    require_targets: bool = True,
    server_options: bool = False,
    fscache: FileSystemCache | None = None,
    program: str = "mypy",
    header: str = HEADER,
    mypyc: bool = False,
)

Source from the content-addressed store, hash-verified

1406
1407
1408def process_options(
1409 args: list[str],
1410 stdout: TextIO | None = None,
1411 stderr: TextIO | None = None,
1412 require_targets: bool = True,
1413 server_options: bool = False,
1414 fscache: FileSystemCache | None = None,
1415 program: str = "mypy",
1416 header: str = HEADER,
1417 mypyc: bool = False,
1418) -> tuple[list[BuildSource], Options]:
1419 """Parse command line arguments.
1420
1421 If a FileSystemCache is passed in, and package_root options are given,
1422 call fscache.set_package_root() to set the cache's package root.
1423
1424 Returns a tuple of: a list of source files, an Options collected from flags.
1425 """
1426 stdout = stdout if stdout is not None else sys.stdout
1427 stderr = stderr if stderr is not None else sys.stderr
1428
1429 parser, _, strict_flag_assignments = define_options(
1430 program, header, stdout, stderr, server_options
1431 )
1432
1433 # Parse arguments once into a dummy namespace so we can get the
1434 # filename for the config file and know if the user requested all strict options.
1435 dummy = argparse.Namespace()
1436 parser.parse_args(args, dummy)
1437 config_file = dummy.config_file
1438 # Don't explicitly test if "config_file is not None" for this check.
1439 # This lets `--config-file=` (an empty string) be used to disable all config files.
1440 if config_file and not os.path.exists(config_file):
1441 parser.error(f"Cannot find config file '{config_file}'")
1442
1443 options = Options()
1444 strict_option_set = False
1445 if mypyc:
1446 # Mypyc has strict_bytes enabled by default
1447 options.strict_bytes = True
1448
1449 def set_strict_flags() -> None:
1450 nonlocal strict_option_set
1451 strict_option_set = True
1452 for dest, value in strict_flag_assignments:
1453 setattr(options, dest, value)
1454
1455 # Parse config file first, so command line can override.
1456 parse_config_file(options, set_strict_flags, config_file, stdout, stderr)
1457
1458 # Set strict flags before parsing (if strict mode enabled), so other command
1459 # line options can override.
1460 if getattr(dummy, "special-opts:strict"):
1461 set_strict_flags()
1462
1463 # Override cache_dir if provided in the environment
1464 environ_cache_dir = os.getenv("MYPY_CACHE_DIR", "")
1465 if environ_cache_dir.strip():

Callers 6

console_entryFunction · 0.90
parse_optionsFunction · 0.90
test_coherenceMethod · 0.90
get_mypy_configFunction · 0.90
mainFunction · 0.85

Calls 15

process_strict_bytesMethod · 0.95
find_moduleMethod · 0.95
OptionsClass · 0.90
parse_config_fileFunction · 0.90
SplitNamespaceClass · 0.90
get_search_dirsFunction · 0.90
SearchPathsClass · 0.90
mypy_pathFunction · 0.90
FindModuleCacheClass · 0.90

Tested by 2

test_coherenceMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…