As mentioned in the accepted answer, using a # type: ignore
comment is effective.
foo: int = "123" # type: ignore
But, as mentioned in that answer's comments, using # type: ignore
can collide with other type checkers (such as mypy). To work around this, Pyright now supports # pyright: ignore
comments (which mypy will not pick up on). This is documented here.
foo: int = "123" # pyright: ignore
A pyright: ignore
comment can be followed by a comma-delimited list of specific pyright rules that should be ignored:
foo: int = "123" # pyright: ignore [reportPrivateUsage, reportGeneralTypeIssues]
Meanwhile, adding the following comment to the top of your module will disable checking of the listed rules for the whole file:
# pyright: reportUndefinedVariable=false, reportGeneralTypeIssues=false
The pyright docs on comments say "typically this comment is placed at or near the top of a code file on its own line."