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

Function _parse_individual_file

mypy/config_parser.py:236–267  ·  view source on GitHub ↗
(
    config_file: str, stderr: TextIO | None = None
)

Source from the content-addressed store, hash-verified

234
235
236def _parse_individual_file(
237 config_file: str, stderr: TextIO | None = None
238) -> tuple[MutableMapping[str, Any], dict[str, _INI_PARSER_CALLABLE], str] | None:
239
240 if not os.path.exists(config_file):
241 return None
242
243 parser: MutableMapping[str, Any]
244 try:
245 if is_toml(config_file):
246 with open(config_file, "rb") as f:
247 toml_data = tomllib.load(f)
248 # Filter down to just mypy relevant toml keys
249 toml_data = toml_data.get("tool", {})
250 if "mypy" not in toml_data:
251 return None
252 toml_data = {"mypy": toml_data["mypy"]}
253 parser = destructure_overrides(toml_data)
254 config_types = toml_config_types
255 else:
256 parser = configparser.RawConfigParser()
257 parser.read(config_file)
258 config_types = ini_config_types
259
260 except (tomllib.TOMLDecodeError, configparser.Error, ConfigTOMLValueError) as err:
261 print(f"{config_file}: {err}", file=stderr)
262 return None
263
264 if os.path.basename(config_file) in defaults.SHARED_CONFIG_NAMES and "mypy" not in parser:
265 return None
266
267 return parser, config_types, config_file
268
269
270def _find_config_file(

Callers 2

_find_config_fileFunction · 0.85
parse_config_fileFunction · 0.85

Calls 6

is_tomlFunction · 0.85
destructure_overridesFunction · 0.85
printFunction · 0.85
existsMethod · 0.80
getMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…