Skip to content

Preserve escaped test section markers in update-data#21606

Open
popsiclelmlm wants to merge 1 commit into
python:masterfrom
popsiclelmlm:codex/mypy-update-data-escape
Open

Preserve escaped test section markers in update-data#21606
popsiclelmlm wants to merge 1 commit into
python:masterfrom
popsiclelmlm:codex/mypy-update-data-escape

Conversation

@popsiclelmlm

Copy link
Copy Markdown

Summary

  • Preserve escaped .test data lines when --update-data rewrites inline error comments.
  • Add a regression test for an escaped [mypy] config section inside a [file mypy.ini] block.

Reproduction

A .test case can include literal section-like lines by escaping the opening bracket, for example:

[file mypy.ini]
\[mypy]
warn_unused_ignores = True

Before this change, running pytest --update-data on a case that touched that file section rewrote the line as [mypy], dropping the escape.

Root cause

parse_test_data unescapes special test-data lines before returning TestItem.data; --update-data then wrote those parsed source lines back directly. That is correct for executing the test case, but not for serializing it back to .test syntax.

Changes

  • Add a small serialization helper for update-data rewrites.
  • Re-escape source lines that start with [ so they stay literal data instead of becoming test section headers.
  • Re-escape source lines that start with --, matching the existing parser escape convention for literal command-like lines.
  • Cover the bracket case in mypy/test/meta/test_update_data.py.

Tests

  • /tmp/mypy-update-data-venv/bin/python -m pytest -q mypy/test/meta/test_update_data.py
  • git diff --check
  • /tmp/mypy-update-data-venv/bin/python -m mypy --config-file mypy_self_check.ini mypy/test/update_data.py mypy/test/meta/test_update_data.py

Screenshots/Logs

Not applicable; test infrastructure change only.

Fixes #17465

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