Skip to content

Add new syntax to let the mypy test file syntax anticipate --pretty output #20811

Open

Description

@wyattscarpenter

The thing that makes #19510 complex is the differences in test output. One possible approach to this is to update the test output to be what it will be if --pretty is enabled. This is complicated by the fact that our current syntax for inline errors in the test data does not actually support what --pretty outputs. Adding that feature could possibly be useful.

(Additionally, #19940 should probably be fixed, and #19546 merged, before this issue is addressed, if one wants the process to be maximally smooth.)

Huh, it hadn't even occurred to me — there's no syntax for multi-line inline comments, is there? Nor for ignoring subsequent lines of a pretty comment in a test...

Originally posted by @wyattscarpenter in #19510 (comment)

Activity

  1. ilevkivskyi commented on Feb 14, 2026

    @ilevkivskyi
    Member

    Or alternatively we can disable it in (most) tests, even if it is on by default. We already do this with some flags, like e.g. we allow empty function bodies in tests.

  2. A5rocks commented on Feb 14, 2026

    @A5rocks
    Collaborator

    I do think it would be nice to have some syntax to annotate spans in the test syntax. Maybe || (or |||) on both sides of the expression? That doesn't show up in our test cases. I think this could be useful even if we don't enable --pretty!

    This could maybe look something like:

    print(5 + ||"5"||)  # E: Unsupported operand types for + ("int" and "str")

    (wow the span for that error is super wrong)

    To implement this, the test case runner could use the JSON output format which I think has start/end col info, check if the spans match, and check that the error message is one of the comments. (I don't think there's a good syntax for matching specific areas to specific spans. Maybe just going in order?)

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