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?
See here for more information.
To ignore all type errors in a given line, you can either append
# ty: ignore
which is specific to ty (ideal for false-positives)
def f(x: int) -> str:
return x # ty: ignore
# type: ignore
which is also used by other type checkers like mypy
def f(x: int) -> str:
return x # type: ignore
a = 10 + "test" # ty: ignore[unsupported-operator]
add_three("one", 5) # ty: ignore[missing-argument, invalid-argument-type]
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