Skip to content

Enable --pretty by default for better error messages#20768

Open
veeceey wants to merge 4 commits intopython:masterfrom
veeceey:feat/issue-19108-enable-pretty-by-default
Open

Enable --pretty by default for better error messages#20768
veeceey wants to merge 4 commits intopython:masterfrom
veeceey:feat/issue-19108-enable-pretty-by-default

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

Summary

This PR enables the --pretty flag by default to provide visually nicer output in error messages. The --pretty option shows error lines with highlighting, uses soft word wrap, and displays source code snippets.

Changes

  • Changed self.pretty = False to self.pretty = True in mypy/options.py
  • Changed default=False to default=True for the --pretty flag in mypy/main.py
  • Updated documentation in docs/source/command_line.rst to reflect the new default and mention --no-pretty

Example Output

With --pretty enabled (new default):

foo.py:13: error: List item 0 has incompatible type "str"; expected "int"  [list-item]
    aa = ["x"]
          ^~~

Without --pretty (using --no-pretty):

foo.py:13: error: List item 0 has incompatible type "str"; expected "int"  [list-item]

Rationale

The additional context makes it easier to see what is wrong. For example, there may be multiple possible expressions which can generate the error, and the highlighting makes this obvious.

Fixes #19108

Changed the default value of --pretty from False to True to provide
visually nicer output by default. Users can still disable it with
--no-pretty if they prefer more concise error messages.

Updated defaults in:
- mypy/options.py: Changed self.pretty = False to True
- mypy/main.py: Changed default=False to default=True for --pretty flag
- docs/source/command_line.rst: Added note about default and --no-pretty

Fixes python#19108
@github-actions

This comment has been minimized.

- Use literal markup for --no-pretty in docs to avoid unknown option warning
- Set pretty=False in test infrastructure so existing test expectations
  remain valid when --pretty is not explicitly passed as a flag
@github-actions

This comment has been minimized.

@wyattscarpenter
Copy link
Contributor

The problem is fixing the test errors, which is what makes #19510 so complicated. Maybe you will find an easier way. But it may be quite difficult.

@veeceey
Copy link
Author

veeceey commented Feb 15, 2026

Thanks for the heads-up! Yeah, I can see the test failures piling up. You're right that this is the trickiest part - the output formatting change ripples through a lot of test cases.

I'm working through the failures systematically. It looks like most of them are in test cases that have hardcoded expectations for the old (non-pretty) output format. I'm updating those to match the new pretty output, though it's definitely tedious.

I'll keep chipping away at it and see if I can find any patterns that'll help batch these updates. Let me know if you spot anything I might be missing!

veeceey and others added 2 commits February 14, 2026 23:18
Fix add_invertible_flag to always use store_true for the flag and
store_false for its inverse, regardless of the default value. The
previous logic inverted the actions when default=True, causing
--pretty to disable pretty mode and --no-pretty to enable it.

Update all test harnesses to explicitly disable pretty mode for tests
that don't opt into it, preventing source code snippets from appearing
in test output that expects non-pretty format.
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

beartype (https://github.com/beartype/beartype)
+ Found 186 errors in 88 files (checked 427 source files)

pyinstrument (https://github.com/joerick/pyinstrument)
+ Found 58 errors in 13 files (checked 32 source files)

CPython (Argument Clinic) (https://github.com/python/cpython)
+ Found 1 error in 1 file (checked 20 source files)

spack (https://github.com/spack/spack)
+ Found 66 errors in 25 files (checked 627 source files)

com2ann (https://github.com/ilevkivskyi/com2ann)
+ Success: no issues found in 2 source files

dacite (https://github.com/konradhalas/dacite)
+ Found 10 errors in 5 files (checked 10 source files)

pytest-robotframework (https://github.com/detachhead/pytest-robotframework)
+ Found 91 errors in 10 files (checked 15 source files)

optuna (https://github.com/optuna/optuna)
+ Found 17 errors in 7 files (checked 324 source files)

spark (https://github.com/apache/spark)
+ Found 44 errors in 19 files (checked 1197 source files)

hydpy (https://github.com/hydpy-dev/hydpy)
+ Found 17 errors in 8 files (checked 417 source files)

psycopg (https://github.com/psycopg/psycopg)
+ Found 14 errors in 5 files (checked 231 source files)

tornado (https://github.com/tornadoweb/tornado)
+ Found 55 errors in 24 files (checked 75 source files)

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ Found 18 errors in 11 files (checked 151 source files)

prefect (https://github.com/PrefectHQ/prefect)
+ Found 1856 errors in 215 files (checked 773 source files)

typeshed-stats (https://github.com/AlexWaygood/typeshed-stats)
+ Found 16 errors in 6 files (checked 15 source files)

pydantic (https://github.com/pydantic/pydantic)
+ Found 745 errors in 58 files (checked 105 source files)

PyGithub (https://github.com/PyGithub/PyGithub)
+ Found 25 errors in 11 files (checked 320 source files)

mkosi (https://github.com/systemd/mkosi)
+ Found 3 errors in 2 files (checked 52 source files)

pylox (https://github.com/sco1/pylox)
+ Found 37 errors in 8 files (checked 305 source files)

bandersnatch (https://github.com/pypa/bandersnatch)
+ Success: no issues found in 59 source files

ppb-vector (https://github.com/ppb/ppb-vector)
+ Found 4 errors in 3 files (checked 28 source files)

cibuildwheel (https://github.com/pypa/cibuildwheel)
+ Found 12 errors in 3 files (checked 35 source files)

mypy-protobuf (https://github.com/dropbox/mypy-protobuf)
+ Found 1 error in 1 file (checked 3 source files)

django-test-migrations (https://github.com/wemake-services/django-test-migrations)
+ Found 2 errors in 1 file (checked 30 source files)

aiohttp (https://github.com/aio-libs/aiohttp)
+ Found 18 errors in 7 files (checked 54 source files)

colour (https://github.com/colour-science/colour)
+ Found 1564 errors in 223 files (checked 696 source files)

python-chess (https://github.com/niklasf/python-chess)
+ Success: no issues found in 8 source files

anyio (https://github.com/agronholm/anyio)
+ Found 18 errors in 5 files (checked 42 source files)

async-utils (https://github.com/mikeshardmind/async-utils)
+ Found 5 errors in 3 files (checked 17 source files)

mypy_primer (https://github.com/hauntsaninja/mypy_primer)
+ Success: no issues found in 9 source files

zipp (https://github.com/jaraco/zipp)
+ Success: no issues found in 7 source files

DateType (https://github.com/glyph/DateType)
+ Found 1 error in 1 file (checked 3 source files)

mypy (https://github.com/python/mypy)
+ Found 3 errors in 1 file (checked 329 source files)

meson (https://github.com/mesonbuild/meson)
+ Found 18 errors in 7 files (checked 244 source files)

graphql-core (https://github.com/graphql-python/graphql-core)
+ Found 1 error in 1 file (checked 314 source files)

altair (https://github.com/vega/altair)
+ Found 58 errors in 28 files (checked 396 source files)

starlette (https://github.com/encode/starlette)
+ Found 146 errors in 33 files (checked 67 source files)

scrapy (https://github.com/scrapy/scrapy)
+ Found 50 errors in 23 files (checked 420 source files)

zulip (https://github.com/zulip/zulip)
+ Found 4512 errors in 458 files (checked 1935 source files)

Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ Found 143 errors in 20 files (checked 36 source files)

speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)
+ Found 100 errors in 13 files (checked 17 source files)

paasta (https://github.com/yelp/paasta)
+ Found 25 errors in 17 files (checked 256 source files)

flake8 (https://github.com/pycqa/flake8)
+ Found 5 errors in 4 files (checked 71 source files)

schemathesis (https://github.com/schemathesis/schemathesis)
+ Found 67 errors in 16 files (checked 201 source files)

strawberry (https://github.com/strawberry-graphql/strawberry)
+ Found 200 errors in 62 files (checked 235 source files)

sockeye (https://github.com/awslabs/sockeye)
+ Found 59 errors in 19 files (checked 37 source files)

cki-lib (https://gitlab.com/cki-project/cki-lib)
+ Found 1223 errors in 63 files (checked 80 source files)

operator (https://github.com/canonical/operator)
+ Found 229 errors in 15 files (checked 29 source files)

pyproject-metadata (https://github.com/pypa/pyproject-metadata)
+ Found 1 error in 1 file (checked 6 source files)

flake8-pyi (https://github.com/PyCQA/flake8-pyi)
+ Success: no issues found in 4 source files

core (https://github.com/home-assistant/core)
+ Found 1284 errors in 527 files (checked 8899 source files)

nionutils (https://github.com/nion-software/nionutils)
+ Success: no issues found in 36 source files

parso (https://github.com/davidhalter/parso)
+ Found 25 errors in 4 files (checked 21 source files)

aioredis (https://github.com/aio-libs/aioredis)
+ Found 17 errors in 4 files (checked 9 source files)

python-sop (https://gitlab.com/dkg/python-sop)
+ Found 2 errors in 1 file (checked 3 source files)

more-itertools (https://github.com/more-itertools/more-itertools)
+ Success: no issues found in 3 source files

CPython (cases_generator) (https://github.com/python/cpython)
+ Success: no issues found in 19 source files

imagehash (https://github.com/JohannesBuchner/imagehash)
+ Found 4 errors in 1 file (checked 1 source file)

sphinx (https://github.com/sphinx-doc/sphinx)
+ Found 264 errors in 54 files (checked 243 source files)

pytest (https://github.com/pytest-dev/pytest)
+ Found 33 errors in 7 files (checked 236 source files)

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ Found 73 errors in 32 files (checked 535 source files)

steam.py (https://github.com/Gobot1234/steam.py)
+ Found 992 errors in 88 files (checked 133 source files)

sympy (https://github.com/sympy/sympy)
+ Found 211 errors in 58 files (checked 1534 source files)

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ Found 236 errors in 15 files (checked 28 source files)

svcs (https://github.com/hynek/svcs)
+ Success: no issues found in 15 source files

urllib3 (https://github.com/urllib3/urllib3)
+ Found 164 errors in 9 files (checked 81 source files)

comtypes (https://github.com/enthought/comtypes)
+ Found 364 errors in 79 files (checked 142 source files)

setuptools (https://github.com/pypa/setuptools)
+ Found 66 errors in 35 files (checked 126 source files)

porcupine (https://github.com/Akuli/porcupine)
+ Found 17 errors in 8 files (checked 78 source files)

downforeveryone (https://github.com/rpdelaney/downforeveryone)
+ Success: no issues found in 16 source files

rich (https://github.com/Textualize/rich)
+ Found 3 errors in 2 files (checked 100 source files)

aiortc (https://github.com/aiortc/aiortc)
+ Found 10 errors in 3 files (checked 32 source files)

rclip (https://github.com/yurijmikhalevich/rclip)
+ Found 18 errors in 4 files (checked 8 source files)

egglog-python (https://github.com/egraphs-good/egglog-python)
+ Success: no issues found in 52 source files

asynq (https://github.com/quora/asynq)
+ Found 3 errors in 2 files (checked 44 source files)

django-stubs (https://github.com/typeddjango/django-stubs)
+ Found 1 error in 1 file (checked 700 source files)

pandas (https://github.com/pandas-dev/pandas)
+ Found 88 errors in 32 files (checked 1455 source files)

janus (https://github.com/aio-libs/janus)
+ Found 2 errors in 1 file (checked 1 source file)

pyp (https://github.com/hauntsaninja/pyp)
+ Success: no issues found in 1 source file

pegen (https://github.com/we-like-parsers/pegen)
+ Success: no issues found in 15 source files

discord.py (https://github.com/Rapptz/discord.py)
+ Found 1004 errors in 88 files (checked 142 source files)

dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ Found 47 errors in 21 files (checked 939 source files)

ibis (https://github.com/ibis-project/ibis)
+ Found 2692 errors in 188 files (checked 563 source files)

trio (https://github.com/python-trio/trio)
+ Found 14 errors in 8 files (checked 144 source files)

pylint (https://github.com/pycqa/pylint)
+ Found 2 errors in 2 files (checked 51 source files)

jax (https://github.com/google/jax)
+ Found 319 errors in 90 files (checked 668 source files)

aiohttp-devtools (https://github.com/aio-libs/aiohttp-devtools)
+ Found 51 errors in 12 files (checked 24 source files)

werkzeug (https://github.com/pallets/werkzeug)
+ Found 985 errors in 30 files (checked 84 source files)

dulwich (https://github.com/dulwich/dulwich)
+ Success: no issues found in 88 source files

black (https://github.com/psf/black)
+ Found 1 error in 1 file (checked 42 source files)

arviz (https://github.com/arviz-devs/arviz)
+ Found 26 errors in 4 files (checked 6 source files)

Expression (https://github.com/cognitedata/Expression)
+ Found 185 errors in 30 files (checked 72 source files)

alerta (https://github.com/alerta/alerta)
+ Found 148 errors in 28 files (checked 140 source files)

koda-validate (https://github.com/keithasaurus/koda-validate)
+ Success: no issues found in 33 source files

scipy (https://github.com/scipy/scipy)
+ Found 745 errors in 91 files (checked 927 source files)

pybind11 (https://github.com/pybind/pybind11)
+ Success: no issues found in 10 source files

alectryon (https://github.com/cpitclaudel/alectryon)
+ Found 28 errors in 11 files (checked 1 source file)

PyWinCtl (https://github.com/Kalmat/PyWinCtl)
+ Found 15 errors in 2 files (checked 5 source files)

pyodide (https://github.com/pyodide/pyodide)
+ Found 176 errors in 44 files (checked 96 source files)

CPython (peg_generator) (https://github.com/python/cpython)
+ Success: no issues found in 17 source files

pycryptodome (https://github.com/Legrandin/pycryptodome)
+ Found 8 errors in 7 files (checked 206 source files)

cryptography (https://github.com/pyca/cryptography)
+ Found 9 errors in 7 files (checked 212 source files)

numpy-stl (https://github.com/WoLpH/numpy-stl)
+ Success: no issues found in 8 source files

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ Found 15 errors in 6 files (checked 343 source files)

packaging (https://github.com/pypa/packaging)
+ Success: no issues found in 18 source files

kornia (https://github.com/kornia/kornia)
+ Found 725 errors in 385 files (checked 486 source files)

bidict (https://github.com/jab/bidict)
+ Success: no issues found in 11 source files

manticore (https://github.com/trailofbits/manticore)
+ Found 126 errors in 16 files (checked 139 source files)

pandera (https://github.com/pandera-dev/pandera)
+ Found 443 errors in 71 files (checked 224 source files)

scikit-learn (https://github.com/scikit-learn/scikit-learn)
+ Found 44 errors in 17 files (checked 572 source files)

poetry (https://github.com/python-poetry/poetry)
+ Found 830 errors in 239 files (checked 370 source files)

pwndbg (https://github.com/pwndbg/pwndbg)
+ Found 36 errors in 19 files (checked 265 source files)

httpx-caching (https://github.com/johtso/httpx-caching)
+ Found 17 errors in 7 files (checked 29 source files)

scipy-stubs (https://github.com/scipy/scipy-stubs)
+ Found 107 errors in 7 files (checked 705 source files)

apprise (https://github.com/caronc/apprise)
+ Found 1547 errors in 173 files (checked 365 source files)

dedupe (https://github.com/dedupeio/dedupe)
+ Found 10 errors in 7 files (checked 30 source files)

pywin32 (https://github.com/mhammond/pywin32)
+ Found 2 errors in 1 file (checked 225 source files)

archinstall (https://github.com/archlinux/archinstall)
+ Found 1 error in 1 file (checked 152 source files)

materialize (https://github.com/MaterializeInc/materialize)
+ Found 338 errors in 117 files (checked 637 source files)

yarl (https://github.com/aio-libs/yarl)
+ Found 416 errors in 6 files (checked 23 source files)

mkdocs (https://github.com/mkdocs/mkdocs)
+ Found 10 errors in 8 files (checked 61 source files)

kopf (https://github.com/nolar/kopf)
+ Found 47 errors in 5 files (checked 84 source files)

websockets (https://github.com/aaugustin/websockets)
+ Found 11 errors in 5 files (checked 53 source files)

stone (https://github.com/dropbox/stone)
+ Found 1 error in 1 file (checked 56 source files)

jinja (https://github.com/pallets/jinja)
+ Found 7 errors in 4 files (checked 25 source files)

python-htmlgen (https://github.com/srittau/python-htmlgen)
+ Found 8 errors in 5 files (checked 32 source files)

zope.interface (https://github.com/zopefoundation/zope.interface)
+ Found 215 errors in 47 files (checked 50 source files)

build (https://github.com/pypa/build)
+ Found 1 error in 1 file (checked 13 source files)

itsdangerous (https://github.com/pallets/itsdangerous)
+ Success: no issues found in 8 source files

rotki (https://github.com/rotki/rotki)
+ Found 433 errors in 43 files (checked 2067 source files)

git-revise (https://github.com/mystor/git-revise)
+ Success: no issues found in 7 source files

pip (https://github.com/pypa/pip)
+ Found 26 errors in 7 files (checked 401 source files)

paroxython (https://github.com/laowantong/paroxython)
+ Found 4 errors in 4 files (checked 20 source files)

static-frame (https://github.com/static-frame/static-frame)
+ Found 175 errors in 23 files (checked 160 source files)

cloud-init (https://github.com/canonical/cloud-init)
+ Found 18 errors in 10 files (checked 588 source files)

cwltool (https://github.com/common-workflow-language/cwltool)
+ Found 2 errors in 2 files (checked 108 source files)

xarray (https://github.com/pydata/xarray)
+ Found 323 errors in 99 files (checked 194 source files)

artigraph (https://github.com/artigraph/artigraph)
+ Found 149 errors in 41 files (checked 84 source files)

freqtrade (https://github.com/freqtrade/freqtrade)
+ Found 312 errors in 22 files (checked 326 source files)

scikit-build-core (https://github.com/scikit-build/scikit-build-core)
+ Found 1 error in 1 file (errors prevented further checking)

schema_salad (https://github.com/common-workflow-language/schema_salad)
+ Found 27 errors in 15 files (checked 53 source files)

bokeh (https://github.com/bokeh/bokeh)
+ Found 22 errors in 9 files (checked 419 source files)

openlibrary (https://github.com/internetarchive/openlibrary)
+ Found 29 errors in 19 files (checked 335 source files)

antidote (https://github.com/Finistere/antidote)
+ Found 3 errors in 3 files (errors prevented further checking)

dragonchain (https://github.com/dragonchain/dragonchain)
+ Found 208 errors in 30 files (checked 141 source files)

AutoSplit (https://github.com/Toufool/AutoSplit)
+ Found 56 errors in 16 files (checked 22 source files)

boostedblob (https://github.com/hauntsaninja/boostedblob)
+ Success: no issues found in 19 source files

pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ Found 85 errors in 14 files (checked 25 source files)

twine (https://github.com/pypa/twine)
+ Found 2 errors in 1 file (checked 16 source files)

isort (https://github.com/pycqa/isort)
+ Success: no issues found in 39 source files

nox (https://github.com/wntrblm/nox)
+ Found 2 errors in 2 files (checked 21 source files)

check-jsonschema (https://github.com/python-jsonschema/check-jsonschema)
+ Found 7 errors in 4 files (checked 38 source files)

pyjwt (https://github.com/jpadilla/pyjwt)
+ Success: no issues found in 12 source files

xarray-dataclasses (https://github.com/astropenguin/xarray-dataclasses)
+ Success: no issues found in 1 source file

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.

Enable --pretty by default

2 participants