Skip to content

(馃悶) --update-data removes escapes聽#17465

Open

Description

@KotlinIsland
[case testSomethingSus]
\[1] + 1
> pytest mypy --update-data

Expected

[case testSomethingSus]
\[1] + 1  # E: Something sus  [sus]

Actual

[case testSomethingSus]
[1] + 1  # E: Something sus  [sus]

Activity

  1. changed the title [-](馃悶) `--update-data` remove escapes[/-] [+](馃悶) `--update-data` removes escapes[/+] on Jul 3, 2024
  2. wyattscarpenter commented on Sep 24, 2025

    @wyattscarpenter
    Contributor

    This is especially annoying, I found out in #19923, when you're trying to make a

    [file foo.ini]
    \[mypy]
    whatever=True
    

    section. --update-data keeps ruining the dang config.

    In case it helps diagnose the problems: I also discovered in https://github.com/python/mypy/pull/19904/files#diff-a359250205cd7c3fa369eb8557c577b353446e840f18a9fe46844232ab3c320fL1018 that it does the same thing with

    #type: ignore[whatever] \
    # E: some message
    

    transforming that into

    #type: ignore[whatever] # E: some message
    

    But luckily that doesn't matter.

  3. wyattscarpenter commented on Sep 27, 2025

    @wyattscarpenter
    Contributor

    This bug is probably the result of this line interpreting \[ bits from parse_test_data in mypy/test/data.py, which is then used by
    _iter_fixes in mypy/test/update_data.py. Presumably these two pieces of logic are working at cross-purposes; One needs to interpret the test case to something Python can execute, and one needs to reproduce it exactly... If I'm right, the simple fix is simply escaping the bracket again as we output to fix lines. If I'm right, this also implies that test-style comments will disappear, which I guess we just haven't tested?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions