Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to ignore pyright checking for one line?

Tags:

python

pyright

I need to ignore pyright checking for one line. Is there any special comment for it?

def create_slog(group: SLogGroup, data: Optional[dict] = None):
    SLog.insert_one(SLog(group=group, data=data))  # pyright: disable

# pyright: disable -- doesn't work

like image 708
Max Block Avatar asked Aug 03 '19 05:08

Max Block


2 Answers

Yes it is with "# type: ignore", for example:

try:
    return int(maybe_digits_string)    # type: ignore
except Exception:
    return None
like image 151
hi2meuk Avatar answered Oct 04 '22 05:10

hi2meuk


As mentioned in the accepted answer's comments, using # type: ignore is effective but it collides with other type checkers (such as mypy).

Pyright now supports # pyright: ignore comments. This is documented here.

foo: int = "123"  # pyright: ignore

This comment can be followed by a comma-delimited list of pyright rules that should be ignored:

foo: int = "123"  # pyright: ignore [reportPrivateUsage, reportGeneralTypeIssues]

Meanwhile, adding the following comment to the top level of your module will disable checking of the listed rules for the whole file:

# pyright: reportUndefinedVariable=false, reportGeneralTypeIssues=false

See the pyright docs on comments.

like image 31
Jasha Avatar answered Oct 04 '22 05:10

Jasha