| 234 | |
| 235 | |
| 236 | def _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 | |
| 270 | def _find_config_file( |