Skip to content

False positive invalid-type-ignore comment for a comment mentioning type: ignore comments #881

@AlexWaygood

Description

@AlexWaygood

Summary

Ty doesn't like this block of code in docstring-adder: https://github.com/astral-sh/docstring-adder/blob/1c87636f0f9b3a5f711c645a6cb0b181f7781464/add_docstrings.py#L234-L265

It complains:

warning[invalid-ignore-comment]
   --> add_docstrings.py:243:47
    |
241 |             new_body = libcst.IndentedBlock(
242 |                 body=[libcst.SimpleStatementLine(body=[docstring_node])],
243 |                 # but preserve `# type: ignore` comments
    |                                               ^ Invalid `type: ignore` comment: no whitespace after `ignore`
244 |                 header=updated_node.body.trailing_whitespace,
245 |             )
    |

A minimal repro of this is:

# make sure to preserve `# type: ignore` comments here:
preserve_the_type_ignore_comments()

https://play.ty.dev/7a1ed259-ceb5-49cf-8643-bedec26f82f1

from my perspective as a human, it feels obvious that this is not intended to be a type: ignore comment that a tool like ty is meant to parse and recognize :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    suppressionRelated to supression of violations e.g. ty:ignore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions