Skip to content

Commit aa16d20

Browse files
committed
Python: Fix false positive for cyclic imports guarded by if False:.
1 parent 921371d commit aa16d20

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

python/ql/src/Imports/Cyclic.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ predicate circular_import(ModuleValue m1, ModuleValue m2) {
2222
ModuleValue stmt_imports(ImportingStmt s) {
2323
exists(string name |
2424
result.importedAs(name) and not name = "__main__" |
25-
name = s.getAnImportedModuleName()
25+
name = s.getAnImportedModuleName() and
26+
s.getASubExpression().pointsTo(result)
2627
)
2728
}
2829

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from typing import TYPE_CHECKING
12

23
if False:
34
import module1
45

6+
if TYPE_CHECKING:
7+
import module1
8+
59
x = 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TYPE_CHECKING = False
2+

0 commit comments

Comments
 (0)