pythonpython-typingty

How to make ty ignore a single line in a source file?


I have been experimenting with Astral's type checker ty recently. As its still pre-release, I run into false-positives from time to time and would like to explicitly tell ty to ignore these.

How can this be done?


Solution

  • See here for more information.

    Suppress rule violation in single line

    To ignore all type errors in a given line, you can either append

    Suppress specific rule violation(s)

    a = 10 + "test"  # ty: ignore[unsupported-operator]
    
    add_three("one", 5)  # ty: ignore[missing-argument, invalid-argument-type]
    

    Suppress all violations in file

    Moreover, # type: ignore can be used at the top of a file to ignore all type errors in that file.

    # type: ignore
    
    def f1(x: int) -> str:
        return x
    
    def f2(x: str) -> int:
        return x