mirror of
https://github.com/github/codeql.git
synced 2026-05-26 17:11:24 +02:00
Uses the existing machinery in ImportResolution.qll, after adding a few convenience predicates. The new modelling actually manages to find a result that the old points-to analysis did not. Apart from that there are no test changes.
31 lines
990 B
Plaintext
31 lines
990 B
Plaintext
/**
|
|
* @name Module imports itself
|
|
* @description A module imports itself
|
|
* @kind problem
|
|
* @tags quality
|
|
* maintainability
|
|
* useless-code
|
|
* @problem.severity recommendation
|
|
* @sub-severity high
|
|
* @precision very-high
|
|
* @id py/import-own-module
|
|
*/
|
|
|
|
import python
|
|
import semmle.python.dataflow.new.DataFlow
|
|
private import semmle.python.dataflow.new.internal.ImportResolution
|
|
|
|
predicate modules_imports_itself(ImportingStmt i, Module m) {
|
|
m = i.getEnclosingModule() and
|
|
ImportResolution::importedBy(i, m) and
|
|
// Exclude `from m import submodule` where the imported member is a submodule of m
|
|
not exists(ImportMember im | im = i.(Import).getAName().getValue() |
|
|
ImportResolution::getImmediateModuleReference(m).asExpr() = im.getModule() and
|
|
ImportResolution::importedBy(i, any(Module sub | sub != m))
|
|
)
|
|
}
|
|
|
|
from ImportingStmt i, Module m
|
|
where modules_imports_itself(i, m)
|
|
select i, "The module '" + ImportResolution::moduleName(m) + "' imports itself."
|