Skip to content

Commit

Permalink
Fix: Exit if any config error
Browse files Browse the repository at this point in the history
  • Loading branch information
cibinmathew committed Aug 15, 2023
1 parent 14418bc commit 7e3f281
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ def parse_section(
elif key == "strict":
pass # Special handling below
else:
print(f"{prefix}Unrecognized option: {key} = {section[key]}", file=stderr)
msg=f"{prefix}Unrecognized option: {key} = {section[key]}"
raise argparse.ArgumentTypeError(msg)
if invert:
dv = getattr(template, options_key, None)
else:
Expand All @@ -493,7 +494,8 @@ def parse_section(
try:
v = ct(section.get(key))
except argparse.ArgumentTypeError as err:
print(f"{prefix}{key}: {err}", file=stderr)
msg=f"{prefix}{key}: {err}"
raise argparse.ArgumentTypeError(msg)
continue
else:
print(f"{prefix}Don't know what type {key} should have", file=stderr)
Expand Down
6 changes: 5 additions & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,11 @@ def set_strict_flags() -> None:
setattr(options, dest, value)

# Parse config file first, so command line can override.
parse_config_file(options, set_strict_flags, config_file, stdout, stderr)
try:
parse_config_file(options, set_strict_flags, config_file, stdout, stderr)
except argparse.ArgumentTypeError as err:
stderr.write(f"{err}")
sys.exit(1)

# Set strict flags before parsing (if strict mode enabled), so other command
# line options can override.
Expand Down

0 comments on commit 7e3f281

Please sign in to comment.