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

Function parse_section

mypy/config_parser.py:483–594  ·  view source on GitHub ↗

Parse one section of a config file. Returns a dict of option values encountered, and a dict of report directories.

(
    prefix: str,
    template: Options,
    set_strict_flags: Callable[[], None],
    section: Mapping[str, Any],
    config_types: dict[str, Any],
    stderr: TextIO = sys.stderr,
)

Source from the content-addressed store, hash-verified

481
482
483def parse_section(
484 prefix: str,
485 template: Options,
486 set_strict_flags: Callable[[], None],
487 section: Mapping[str, Any],
488 config_types: dict[str, Any],
489 stderr: TextIO = sys.stderr,
490) -> tuple[dict[str, object], dict[str, str]]:
491 """Parse one section of a config file.
492
493 Returns a dict of option values encountered, and a dict of report directories.
494 """
495 results: dict[str, object] = {}
496 report_dirs: dict[str, str] = {}
497
498 # Because these fields exist on Options, without proactive checking, we would accept them
499 # and crash later
500 invalid_options = {
501 "enabled_error_codes": "enable_error_code",
502 "disabled_error_codes": "disable_error_code",
503 }
504
505 for key in section:
506 invert = False
507 # Here we use `key` for original config section key, and `options_key` for
508 # the corresponding Options attribute.
509 options_key = key
510 # Match aliasing for deprecated config option name.
511 if options_key == "allow_redefinition_new":
512 options_key = "allow_redefinition"
513 if key in config_types:
514 ct = config_types[key]
515 elif key in invalid_options:
516 print(
517 f"{prefix}Unrecognized option: {key} = {section[key]}"
518 f" (did you mean {invalid_options[key]}?)",
519 file=stderr,
520 )
521 continue
522 else:
523 dv = getattr(template, options_key, None)
524 if dv is None:
525 if key.endswith("_report"):
526 report_type = key[:-7].replace("_", "-")
527 if report_type in defaults.REPORTER_NAMES:
528 report_dirs[report_type] = str(section[key])
529 else:
530 print(f"{prefix}Unrecognized report type: {key}", file=stderr)
531 continue
532 if key.startswith("x_"):
533 pass # Don't complain about `x_blah` flags
534 elif key.startswith("no_") and hasattr(template, options_key[3:]):
535 options_key = options_key[3:]
536 invert = True
537 elif key.startswith("allow") and hasattr(template, "dis" + options_key):
538 options_key = "dis" + options_key
539 invert = True
540 elif key.startswith("disallow") and hasattr(template, options_key[3:]):

Callers 2

parse_config_fileFunction · 0.85
parse_mypy_commentsFunction · 0.85

Calls 12

printFunction · 0.85
getattrFunction · 0.85
strClass · 0.85
hasattrFunction · 0.85
typeClass · 0.85
isinstanceFunction · 0.85
convert_to_booleanFunction · 0.85
replaceMethod · 0.80
set_strict_flagsFunction · 0.70
endswithMethod · 0.45
startswithMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…