Python: Fix queries and tests

This commit is contained in:
Taus
2025-11-26 13:59:23 +00:00
parent b9a5b3b628
commit cd1619b43e
4 changed files with 8 additions and 5 deletions

View File

@@ -36,7 +36,7 @@ predicate same_value(Expr left, Expr right) {
}
predicate maybe_defined_in_outer_scope(Name n) {
exists(SsaVariable v | v.getAUse().getNode() = n | v.maybeUndefined())
exists(SsaVariableWithPointsTo v | v.getAUse().getNode() = n | v.maybeUndefined())
}
/*

View File

@@ -62,7 +62,7 @@ predicate undefined_use_in_function(Name u) {
not u.getEnclosingModule().(ImportTimeScope).definesName(u.getId()) and
not exists(ModuleValue m | m.getScope() = u.getEnclosingModule() | m.hasAttribute(u.getId())) and
not globallyDefinedName(u.getId()) and
not exists(SsaVariable var | var.getAUse().getNode() = u and not var.maybeUndefined()) and
not exists(SsaVariableWithPointsTo var | var.getAUse().getNode() = u and not var.maybeUndefined()) and
not guarded_against_name_error(u) and
not (u.getEnclosingModule().isPackageInit() and u.getId() = "__path__")
}
@@ -70,7 +70,7 @@ predicate undefined_use_in_function(Name u) {
predicate undefined_use_in_class_or_module(Name u) {
exists(GlobalVariable v | u.uses(v)) and
not u.getScope().getScope*() instanceof Function and
exists(SsaVariable var | var.getAUse().getNode() = u | var.maybeUndefined()) and
exists(SsaVariableWithPointsTo var | var.getAUse().getNode() = u | var.maybeUndefined()) and
not guarded_against_name_error(u) and
not exists(ModuleValue m | m.getScope() = u.getEnclosingModule() | m.hasAttribute(u.getId())) and
not (u.getEnclosingModule().isPackageInit() and u.getId() = "__path__") and

View File

@@ -18,7 +18,9 @@ private import semmle.python.types.ImportTime
/* Local variable part */
predicate initialized_as_local(PlaceHolder use) {
exists(SsaVariable l, Function f | f = use.getScope() and l.getAUse() = use.getAFlowNode() |
exists(SsaVariableWithPointsTo l, Function f |
f = use.getScope() and l.getAUse() = use.getAFlowNode()
|
l.getVariable() instanceof LocalVariable and
not l.maybeUndefined()
)

View File

@@ -1,5 +1,6 @@
import python
private import LegacyPointsTo
from SsaVariable var
from SsaVariableWithPointsTo var
where var.maybeUndefined()
select var.getDefinition().getLocation().getStartLine(), var.toString()