quora / pyanalyze

A Python type checker
Apache License 2.0
326 stars 36 forks source link

Ignore statement not working for some cases (`import_failed`) #699

Open mflova opened 10 months ago

mflova commented 10 months ago

So far I found this strange behaviour when trying to silence some import_failed error codes. Here is a minimal example:

# Error not reported in this file -> OK
import a  # static analysis: ignore
# Error reported in this file -> NOK
from __future__ import annotations

import a  # static analysis: ignore
# Error not reported in this file -> OK
# static analysis: ignore
from __future__ import annotations

import a
JelleZijlstra commented 10 months ago

The problem here is that import_failed is not reported at a particular line, because it doesn't happen while pyanalyze is visiting the file, but while it's trying to import it. If this error happens, it will essentially make it impossible for pyanalyze to check the rest of the file. I'm not sure that's something I should change, as it's an essential part of pyanalyze that it works by importing the file.

Your last example works because # static analysis: ignore on a line by itself at the beginning of the file ignores the entire file.

mflova commented 10 months ago

It makes sense. I do not think it is worth to change it then. Thanks for the feedback!