mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Python: Autoformat everything using qlformat.
Will need subsequent PRs fixing up test failures (due to deprecated methods moving around), but other than that everything should be straight-forward.
This commit is contained in:
@@ -16,27 +16,27 @@
|
||||
import python
|
||||
|
||||
predicate is_condition(Expr cond) {
|
||||
exists(If i | i.getTest() = cond) or
|
||||
exists(IfExp ie | ie.getTest() = cond)
|
||||
exists(If i | i.getTest() = cond) or
|
||||
exists(IfExp ie | ie.getTest() = cond)
|
||||
}
|
||||
|
||||
/* Treat certain unmodified builtins as constants as well. */
|
||||
predicate effective_constant(Name cond) {
|
||||
exists(GlobalVariable var | var = cond.getVariable() and not exists(NameNode f | f.defines(var)) |
|
||||
var.getId() = "True" or var.getId() = "False" or var.getId() = "NotImplemented"
|
||||
)
|
||||
exists(GlobalVariable var | var = cond.getVariable() and not exists(NameNode f | f.defines(var)) |
|
||||
var.getId() = "True" or var.getId() = "False" or var.getId() = "NotImplemented"
|
||||
)
|
||||
}
|
||||
|
||||
predicate test_makes_code_unreachable(Expr cond) {
|
||||
exists(If i | i.getTest() = cond | i.getStmt(0).isUnreachable() or i.getOrelse(0).isUnreachable())
|
||||
or
|
||||
exists(While w | w.getTest() = cond and w.getStmt(0).isUnreachable())
|
||||
exists(If i | i.getTest() = cond | i.getStmt(0).isUnreachable() or i.getOrelse(0).isUnreachable())
|
||||
or
|
||||
exists(While w | w.getTest() = cond and w.getStmt(0).isUnreachable())
|
||||
}
|
||||
|
||||
from Expr cond
|
||||
where
|
||||
is_condition(cond) and
|
||||
(cond.isConstant() or effective_constant(cond)) and
|
||||
/* Ignore cases where test makes code unreachable, as that is handled in different query */
|
||||
not test_makes_code_unreachable(cond)
|
||||
is_condition(cond) and
|
||||
(cond.isConstant() or effective_constant(cond)) and
|
||||
/* Ignore cases where test makes code unreachable, as that is handled in different query */
|
||||
not test_makes_code_unreachable(cond)
|
||||
select cond, "Testing a constant will always give the same result."
|
||||
|
||||
Reference in New Issue
Block a user