Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when parsing error code config with typo #16005

Merged
merged 3 commits into from
Sep 1, 2023

Conversation

hauntsaninja
Copy link
Collaborator

Fixes #16002

@github-actions

This comment has been minimized.

elif key in ("enabled_error_codes", "disabled_error_codes"):
# These should be "enable_error_code" and "disable_error_code". But because these fields
# exist on Options, we would otherwise accept them here and crash later.
print(f"{prefix}Unrecognized option: {key} = {section[key]}", file=stderr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have special-case code anyway, maybe we can add a note pointing to the right version?

Suggested change
print(f"{prefix}Unrecognized option: {key} = {section[key]}", file=stderr)
print(f"{prefix}Unrecognized option: {key} = {section[key]} (did you mean {key[:-1]!r}?)", file=stderr)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you've got an extra d :-) thanks for the suggestion!

@github-actions

This comment has been minimized.

suggestion = {
"enabled_error_codes": "enable_error_code",
"disabled_error_codes": "disable_error_code",
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move the dict outside of the loop and check against e.g. key in option_replacements to avoid the repetition?

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja merged commit 803f610 into python:master Sep 1, 2023
17 checks passed
@hauntsaninja hauntsaninja deleted the error-code-config branch September 1, 2023 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError when mypy.ini contains disabled_error_codes
3 participants