Skip to content

Using commas wrong in a type ignore makes there be an error code in there that is the empty string #20038

Closed

Description

@wyattscarpenter

Expected behavior:

[case testErrorCodeWarnUnusedIgnores9_testUnusedIgnoreSloppyFormattingNotEmptyBrackets]
# flags: --warn-unused-ignores
1 + "ok" + "ok".foo # type: ignore[  operator,attr-defined]
1 + "ok" + "ok".foo # type: ignore[  ,operator,attr-defined] # E: Unused "type: ignore" comment  [unused-ignore]
1 + "ok" + "ok".foo # type: ignore[  operator,attr-defined,] # E: Unused "type: ignore" comment  [unused-ignore]
1 + "ok" + "ok".foo # type: ignore[  operator,attr-defined,,] # E: Unused "type: ignore" comment  [unused-ignore]

[case testErrorCodeWarnUnusedIgnores10_testUnusedIgnoreSloppyFormattingEmptyBrackets]
# flags: --warn-unused-ignores
1+1 # type: ignore    # E: Unused "type: ignore" comment  [unused-ignore]
1+1 # type: ignore[]  # E: Unused "type: ignore" comment  [unused-ignore]
1+1 # type: ignore[ ] # E: Unused "type: ignore" comment  [unused-ignore]
1+1 # type: ignore[,,, ] # E: Unused "type: ignore" comment  [unused-ignore]

Actual behavior:

When there is a trailing comma, a leading comma, or other comma abuse, the error is Unused "type: ignore[]" comment instead, because the empty string error code still counts.

I could easily have suppressed this symptom at the site of the unused ignores warning, but this seems like something that should probably be fixed at the source, to avoid other almost-invisible erroneous behavior from popping up later.

Activity

  1. codenamenam commented on Oct 12, 2025

    @codenamenam
    Contributor

    This would be fixed by #20052

  2. wyattscarpenter commented on Oct 12, 2025

    @wyattscarpenter
    ContributorAuthor

    Wow, thanks!

    Thanks also for fixing my proposed test, which are a little confused in the OP, due to me working on #19904 simultaneously.

  3. codenamenam commented on Oct 12, 2025

    @codenamenam
    Contributor

    well, I just made some minor adjustments based on your test cases. Thank you for your contribution!

  4. added a commit that references this issue on Nov 28, 2025
    4f5425e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-ignore# type: ignore comments

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions