Skip to content

Preserve escaped test data section lines#21774

Open
tarun-bandi wants to merge 1 commit into
python:masterfrom
tarun-bandi:agent/preserve-update-data-escapes
Open

Preserve escaped test data section lines#21774
tarun-bandi wants to merge 1 commit into
python:masterfrom
tarun-bandi:agent/preserve-update-data-escapes

Conversation

@tarun-bandi

Copy link
Copy Markdown

Fixes #17465.

parse_test_data() unescapes lines that begin with \[ so they can be treated as source text rather than .test section headers. When --update-data rewrites a test case, it was writing the parsed source line back directly, so an escaped line such as \[mypy] became [mypy] and could be parsed as a new section on the next run.

This keeps updated source lines escaped when they would otherwise look like section headers after being written back. It covers both unchanged lines in [file ...] sections and source lines that gain an inline # E: comment ending with an error code.

Validation:

  • /Users/bandi/Documents/Codex/2026-07-24/new-chat/work/mypy_venv/bin/python -m pytest mypy/test/test_update_data.py -q
  • PYTHONPYCACHEPREFIX=/Users/bandi/Documents/Codex/2026-07-24/new-chat/work/.pycache /Users/bandi/Documents/Codex/2026-07-24/new-chat/work/mypy_venv/bin/python -m py_compile mypy/test/update_data.py mypy/test/test_update_data.py
  • git diff --cached --check

@tarun-bandi
tarun-bandi force-pushed the agent/preserve-update-data-escapes branch from a27210e to 398a49e Compare July 25, 2026 04:07
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.

(🐞) --update-data removes escapes

1 participant