Skip to content

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

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

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