-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Enable pretty by default #19510
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
base: master
Are you sure you want to change the base?
Enable pretty by default #19510
Conversation
I'll make sure to ping. |
This comment has been minimized.
This comment has been minimized.
964f17f
to
8214b19
Compare
This comment has been minimized.
This comment has been minimized.
e60744f
to
8afae7a
Compare
Hi, looks like the
This seems to be an issue with the CI environment and is unrelated to my code changes. I've re-triggered the CI once by pushing an empty commit, but the failure is persistent. Could a maintainer with permissions please take a look or re-run the failed job? It seems to be the only thing blocking the CI from going green. Thanks! |
This comment has been minimized.
This comment has been minimized.
Yep, this has nothing to do with your PR, |
Fixes docs build failure discovered in #19510. Updated setuptools URL too because previous CI runs say that > intersphinx inventory has moved: https://setuptools.readthedocs.io/en/latest/objects.inv -> https://setuptools.pypa.io/en/latest/objects.inv
JFYI the docs issue is now fixed on master |
Change the default mypy output to be pretty-printed, providing users with more readable error messages that include code context out-of-the-box. This commit implements the core logic for this feature: - In 'mypy/options.py', the default value for 'pretty' is set to 'True'. - In 'mypy/main.py', the command-line flags are reconfigured: - '--no-pretty' is now the primary, user-facing flag to disable the pretty printing. - The old '--pretty' flag is deprecated and hidden from help text to reflect that the pretty output is now default. This change intentionally breaks the test suite, which will be fixediIn subsequent commits by adapting the test runners. Part of python#19108
This commit adapts the main test runner (`TypeCheckSuite`) to handle the new pretty-by-default behaviour. - For tests with a `# flags: ` line `--no-pretty` is now injected unless `--pretty` is explicitly requested. - For tests without any flags, `options.pretty` is directly set to `False` to ensure plain output. This strategy avoids modifying thousands of individual test-data files.
This commit adapts the `CmdlineSuite` runner to handle the new pretty-by-default behavior. The `parse_args` helper in `mypy/test/testcmdline.py` is modified to inject the `--no-pretty` flag into the arguments parsed from '# cmd:' lines in test cases. This ensures that command-line-driven tests, which run in a separate subprocess and bypass other test helpers, are also executed in non-pretty mode by default. Part of python#19108.
This commit adapts the `pythoneval` test runner to handle the new pretty-by-default behavior. The `test_python_evaluation` function in `mypy/test/testpythoneval.py` now injects the `--no-pretty` flag by default into the mypy command line it constructs. Logic is also included to respect a `# flags: --pretty` directive, ensuring that tests designed to check pretty-printing still work correctly. Part of python#19108.
This commit modifies the `test_error_stream` runner to set `options.pretty = False`, ensuring its tests continue to pass with the new pretty-by-default behavior. Part of python#19108.
This commit adapts the `DaemonSuite` test runner and its corresponding data files to accommodate the new pretty-by-default behavior. This fix is nuanced due to the stateful, client-server nature of the daemon and required a two-part approach: 1. **Central Logic:** The `run_cmd` helper in `mypy/test/testdaemon.py` was modified to inject `--no-pretty` only into state-setting subcommands (`run`, `check`). This handles the majority of daemon tests. 2. **Manual Overrides:** A number of test cases in `daemon.test` were manually updated. This was necessary for tests that start the daemon with `dmypy start` or have other unique requirements, ensuring the server is correctly configured in non-pretty mode from the outset. This combined strategy ensures the entire daemon test suite passes. Part of python#19108.
This commit adapts the `PEP561Suite` test runner to handle the new pretty-by-default behavior. The `parse_mypy_args` helper in `mypy/test/testpep561.py` is modified to inject the `--no-pretty` flag into the arguments parsed from '# flags:' lines in test cases. Part of python#19108.
This commit adapts several unit tests in the `StubtestMiscUnit` suite to handle the new pretty-by-default behavior. Because the `stubtest` runner is a distinct command-line tool, injecting the `--no-pretty` flag was not feasible as it's an unrecognized argument. Instead, the `assert` statements in the failing tests have been updated to match the new, pretty-printed error output from mypy. Part of python#19108.
This commit updates the user-facing documentation to reflect that pretty-printing is now the default output format. - The `--pretty` flag documentation in `command_line.rst` has been replaced with documentation for the new `--no-pretty` flag. - The `config_file.rst` documentation for the `pretty` option has been updated to state that its default is now `True`. Fixes python#19108.
73c1b5b
to
d67c367
Compare
for more information, see https://pre-commit.ci
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This change enables mypy's "pretty" error reporting by default to provide a better out-of-the-box experience for users.
Fixes #19108.
Core Changes
pretty
option is nowTrue
.--no-pretty
is the primary, user-facing flag to disable pretty-printing.--pretty
flag is now a no-op (for backward compatibility) and has been hidden from the--help
message.Test Suite Modifications
Enabling
pretty
output by default caused widespread test failures, as most tests were written to expect the old plain output. Instead of modifying thousands of test case files, this PR introduces targeted fixes into the central test runners to default them to--no-pretty
mode.This required modifying several distinct test runners:
TypeCheckSuite
: The main test runner's option parsing was updated inmypy/test/helpers.py
.CmdlineSuite
: The raw command-line argument parser inmypy/test/testcmdline.py
was updated.PEP561Suite
& others: Other smaller test runners (testpythoneval
,testerrorstream
) were also adapted.DaemonSuite
: This was the most complex fix due to the daemon's stateful, client-server architecture. The solution required a combination of central logic and manual test case edits:run_cmd
helper inmypy/test/testdaemon.py
was updated to inject--no-pretty
only into state-setting subcommands (run
,check
). This handles the majority of cases.daemon.test
were manually updated based on how they interact with the daemon's lifecycle:$ dmypy start
, the--no-pretty
flag was added to the server's default flags (e.g.,start -- --no-pretty
) to set the server's state for the entire run.$ dmypy run
), the flag was passed via the--
separator (e.g.,run -- --no-pretty test.py
) to configure the new server instance.Stubtest
Unit Tests: The handful ofstubtest
tests were updated manually to assert against the new pretty-printed output, as their runner does not accept formatting flags.This overall approach keeps the
git diff
minimal and isolates the test-related changes to the test infrastructure itself.Documentation
--no-pretty
flag.