MCPcopy Index your code
hub / github.com/python/mypy / destructure_overrides

Function destructure_overrides

mypy/config_parser.py:400–480  ·  view source on GitHub ↗

Take the new [[tool.mypy.overrides]] section array in the pyproject.toml file, and convert it back to a flatter structure that the existing config_parser can handle. E.g. the following pyproject.toml file: [[tool.mypy.overrides]] module = [ "a.b", "b

(toml_data: dict[str, Any])

Source from the content-addressed store, hash-verified

398
399
400def destructure_overrides(toml_data: dict[str, Any]) -> dict[str, Any]:
401 """Take the new [[tool.mypy.overrides]] section array in the pyproject.toml file,
402 and convert it back to a flatter structure that the existing config_parser can handle.
403
404 E.g. the following pyproject.toml file:
405
406 [[tool.mypy.overrides]]
407 module = [
408 "a.b",
409 "b.*"
410 ]
411 disallow_untyped_defs = true
412
413 [[tool.mypy.overrides]]
414 module = 'c'
415 disallow_untyped_defs = false
416
417 Would map to the following config dict that it would have gotten from parsing an equivalent
418 ini file:
419
420 {
421 "mypy-a.b": {
422 disallow_untyped_defs = true,
423 },
424 "mypy-b.*": {
425 disallow_untyped_defs = true,
426 },
427 "mypy-c": {
428 disallow_untyped_defs: false,
429 },
430 }
431 """
432 if "overrides" not in toml_data["mypy"]:
433 return toml_data
434
435 if not isinstance(toml_data["mypy"]["overrides"], list):
436 raise ConfigTOMLValueError(
437 "tool.mypy.overrides sections must be an array. Please make "
438 "sure you are using double brackets like so: [[tool.mypy.overrides]]"
439 )
440
441 result = toml_data.copy()
442 for override in result["mypy"]["overrides"]:
443 if "module" not in override:
444 raise ConfigTOMLValueError(
445 "toml config file contains a [[tool.mypy.overrides]] "
446 "section, but no module to override was specified."
447 )
448
449 if isinstance(override["module"], str):
450 modules = [override["module"]]
451 elif isinstance(override["module"], list):
452 modules = override["module"]
453 else:
454 raise ConfigTOMLValueError(
455 "toml config file contains a [[tool.mypy.overrides]] "
456 "section with a module value that is not a string or a list of "
457 "strings"

Callers 1

_parse_individual_fileFunction · 0.85

Calls 4

isinstanceFunction · 0.85
copyMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…