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

stubtest does not correctly handle disable_error_code option when --mypy-config-file is supplied #17628

Closed
sobolevn opened this issue Aug 3, 2024 · 0 comments
Assignees
Labels
bug mypy got something wrong topic-configuration Configuration files and flags topic-stubtest

Comments

@sobolevn
Copy link
Member

sobolevn commented Aug 3, 2024

When --mypy-config-file is passed to stubtest is uses parse_config_file function. Which does not handle disable_error_code setting correctly. Since it is done in another place (mypy/main.py):

mypy/mypy/main.py

Lines 1339 to 1353 in a0dbbd5

# Process `--enable-error-code` and `--disable-error-code` flags
disabled_codes = set(options.disable_error_code)
enabled_codes = set(options.enable_error_code)
valid_error_codes = set(error_codes.keys())
invalid_codes = (enabled_codes | disabled_codes) - valid_error_codes
if invalid_codes:
parser.error(f"Invalid error code(s): {', '.join(sorted(invalid_codes))}")
options.disabled_error_codes |= {error_codes[code] for code in disabled_codes}
options.enabled_error_codes |= {error_codes[code] for code in enabled_codes}
# Enabling an error code always overrides disabling
options.disabled_error_codes -= options.enabled_error_codes

There are similar cases of options that are post-processed there, but not in parse_config_file, but let's fix them one by one to reduce potential regressions.

I propose adding process_error_codes method to Options object so it can be used in both main.py and stubtest.py (and others like stubgen in the future).

Found while working on python/typeshed#12463

@sobolevn sobolevn added bug mypy got something wrong topic-stubtest topic-configuration Configuration files and flags labels Aug 3, 2024
@sobolevn sobolevn self-assigned this Aug 3, 2024
@sobolevn sobolevn closed this as completed Aug 3, 2024
sobolevn added a commit that referenced this issue Aug 5, 2024
sobolevn added a commit that referenced this issue Aug 14, 2024
This adds a test for incorrect error code in `stubtest`'s config file.

Refs #17628

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-configuration Configuration files and flags topic-stubtest
Projects
None yet
Development

No branches or pull requests

1 participant