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

Function parse_options

mypy/test/helpers.py:386–421  ·  view source on GitHub ↗

Parse comments like '# flags: --foo' in a test case.

(
    program_text: str, testcase: DataDrivenTestCase, incremental_step: int
)

Source from the content-addressed store, hash-verified

384
385
386def parse_options(
387 program_text: str, testcase: DataDrivenTestCase, incremental_step: int
388) -> Options:
389 """Parse comments like '# flags: --foo' in a test case."""
390 options = Options()
391 flags = re.search("# flags: (.*)$", program_text, flags=re.MULTILINE)
392 if incremental_step > 1:
393 flags2 = re.search(f"# flags{incremental_step}: (.*)$", program_text, flags=re.MULTILINE)
394 if flags2:
395 flags = flags2
396
397 if flags:
398 flag_list = flags.group(1).split()
399 flag_list.append("--no-site-packages") # the tests shouldn't need an installed Python
400 targets, options = process_options(flag_list, require_targets=False)
401 if targets:
402 # TODO: support specifying targets via the flags pragma
403 raise RuntimeError("Specifying targets via the flags pragma is not supported.")
404 if "--show-error-codes" not in flag_list:
405 options.hide_error_codes = True
406 else:
407 flag_list = []
408 options = Options()
409 options.error_summary = False
410 options.hide_error_codes = True
411
412 # Allow custom python version to override testfile_pyversion.
413 if all(flag.split("=")[0] != "--python-version" for flag in flag_list):
414 options.python_version = testfile_pyversion(testcase.file)
415
416 if testcase.config.getoption("--mypy-verbose"):
417 options.verbosity = testcase.config.getoption("--mypy-verbose")
418 if testcase.config.getoption("--mypy-num-workers"):
419 options.num_workers = testcase.config.getoption("--mypy-num-workers")
420
421 return options
422
423
424def split_lines(*streams: bytes) -> list[str]:

Callers 8

get_semanal_optionsFunction · 0.90
get_optionsMethod · 0.90
run_caseMethod · 0.90
buildMethod · 0.90
test_transformFunction · 0.90
run_case_onceMethod · 0.90
test_parse_errorFunction · 0.90
run_caseMethod · 0.90

Calls 8

OptionsClass · 0.90
process_optionsFunction · 0.90
RuntimeErrorClass · 0.85
allFunction · 0.85
testfile_pyversionFunction · 0.85
splitMethod · 0.80
groupMethod · 0.80
appendMethod · 0.80

Tested by 8

get_semanal_optionsFunction · 0.72
get_optionsMethod · 0.72
run_caseMethod · 0.72
buildMethod · 0.72
test_transformFunction · 0.72
run_case_onceMethod · 0.72
test_parse_errorFunction · 0.72
run_caseMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…