Files
codeql/python/ql/src/Imports/CyclicImport.ql
Taus 5b63b4957c Python: Fix query tests
Mostly just adding `private import LegacyPointsTo`. Sometimes getting
rid of other imports that are superceded by that module.
2025-11-26 12:30:30 +00:00

28 lines
821 B
Plaintext

/**
* @name Cyclic import
* @description Module forms part of an import cycle, thereby indirectly importing itself.
* @kind problem
* @tags reliability
* maintainability
* modularity
* @problem.severity recommendation
* @sub-severity low
* @precision high
* @id py/cyclic-import
*/
import python
import Cyclic
private import LegacyPointsTo
from ModuleValue m1, ModuleValue m2, Stmt imp
where
imp.getEnclosingModule() = m1.getScope() and
stmt_imports(imp) = m2 and
circular_import(m1, m2) and
m1 != m2 and
// this query finds all cyclic imports that are *not* flagged by ModuleLevelCyclicImport
not failing_import_due_to_cycle(m2, m1, _, _, _, _) and
not exists(If i | i.isNameEqMain() and i.contains(imp))
select imp, "Import of module $@ begins an import cycle.", m2, m2.getName()