Skip to content

Commit 64863ef

Browse files
restore the existence check
1 parent d604151 commit 64863ef

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

mypy/config_parser.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,18 @@ def split_commas(value: str) -> list[str]:
261261

262262

263263
def _parse_individual_file(
264-
config_file: str, stderr: TextIO | None = None
264+
config_filename: str, stderr: TextIO | None = None
265265
) -> tuple[_ParserHelper, dict[str, _INI_PARSER_CALLABLE], str] | None:
266+
"""Internal utility function for doing the first part of parsing config files.
267+
Returns None for most conditions where the file doesn't exist or isn't about mypy
268+
or isn't formatted correctly. Sometimes this prints an error."""
269+
270+
if not os.path.exists(config_filename):
271+
return None
272+
266273
try:
267-
if is_toml(config_file):
268-
with open(config_file, "rb") as f:
274+
if is_toml(config_filename):
275+
with open(config_filename, "rb") as f:
269276
# tomllib.load returns dict[str, Any], so it doesn't complain about any type on the lhs.
270277
# However, this is probably the actual return type of tomllib.load,
271278
# assuming the optional parse_float is not used. (Indeed, we do not use it.)
@@ -290,7 +297,7 @@ def _parse_individual_file(
290297
config_types = toml_config_types
291298
else:
292299
parser = configparser.RawConfigParser()
293-
parser.read(config_file)
300+
parser.read(config_filename)
294301
config_types = ini_config_types
295302

296303
except (
@@ -299,13 +306,13 @@ def _parse_individual_file(
299306
configparser.Error,
300307
MypyConfigTOMLValueError,
301308
) as err:
302-
print(f"{config_file}: {err}", file=stderr)
309+
print(f"{config_filename}: {err}", file=stderr)
303310
return None
304311

305-
if os.path.basename(config_file) in defaults.SHARED_CONFIG_NAMES and "mypy" not in parser:
312+
if os.path.basename(config_filename) in defaults.SHARED_CONFIG_NAMES and "mypy" not in parser:
306313
return None
307314

308-
return parser, config_types, config_file
315+
return parser, config_types, config_filename
309316

310317

311318
def _find_config_file(

0 commit comments

Comments
 (0)