Python: Fix query tests

Mostly just adding `private import LegacyPointsTo`. Sometimes getting
rid of other imports that are superceded by that module.
This commit is contained in:
Taus
2025-10-30 23:06:26 +00:00
parent 2732a652ab
commit 5b63b4957c
52 changed files with 49 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
import python import python
private import semmle.python.pointsto.PointsTo private import LegacyPointsTo
/** A helper class for UndefinedClassAttribute.ql and MaybeUndefinedClassAttribute.ql */ /** A helper class for UndefinedClassAttribute.ql and MaybeUndefinedClassAttribute.ql */
class CheckClass extends ClassObject { class CheckClass extends ClassObject {

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate does_nothing(PyFunctionObject f) { predicate does_nothing(PyFunctionObject f) {
not exists(Stmt s | s.getScope() = f.getFunction() | not exists(Stmt s | s.getScope() = f.getFunction() |

View File

@@ -13,6 +13,7 @@
import python import python
import Equality import Equality
private import LegacyPointsTo
predicate class_stores_to_attribute(ClassValue cls, SelfAttributeStore store, string name) { predicate class_stores_to_attribute(ClassValue cls, SelfAttributeStore store, string name) {
exists(FunctionValue f | exists(FunctionValue f |

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
ClassObject left_base(ClassObject type, ClassObject base) { ClassObject left_base(ClassObject type, ClassObject base) {
exists(int i | i > 0 and type.getBaseType(i) = base and result = type.getBaseType(i - 1)) exists(int i | i > 0 and type.getBaseType(i) = base and result = type.getBaseType(i - 1))

View File

@@ -12,6 +12,7 @@
import python import python
import ClassAttributes import ClassAttributes
private import LegacyPointsTo
predicate guarded_by_other_attribute(SelfAttributeRead a, CheckClass c) { predicate guarded_by_other_attribute(SelfAttributeRead a, CheckClass c) {
c.sometimesDefines(a.getName()) and c.sometimesDefines(a.getName()) and

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate mutates_descriptor(ClassObject cls, SelfAttributeStore s) { predicate mutates_descriptor(ClassObject cls, SelfAttributeStore s) {
cls.isDescriptorType() and cls.isDescriptorType() and

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
class InitCallStmt extends ExprStmt { class InitCallStmt extends ExprStmt {
InitCallStmt() { InitCallStmt() {

View File

@@ -11,6 +11,7 @@
*/ */
import python import python
private import LegacyPointsTo
from PropertyObject prop, ClassObject cls from PropertyObject prop, ClassObject cls
where cls.declaredAttribute(_) = prop and not cls.failedInference() and not cls.isNewStyle() where cls.declaredAttribute(_) = prop and not cls.failedInference() and not cls.isNewStyle()

View File

@@ -14,6 +14,7 @@
*/ */
import python import python
private import LegacyPointsTo
from ClassValue c from ClassValue c
where not c.isBuiltin() and not c.isContextManager() and exists(c.declaredAttribute("__del__")) where not c.isBuiltin() and not c.isContextManager() and exists(c.declaredAttribute("__del__"))

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
from ClassObject c from ClassObject c
where not c.isNewStyle() and c.declaresAttribute("__slots__") and not c.failedInference() where not c.isNewStyle() and c.declaresAttribute("__slots__") and not c.failedInference()

View File

@@ -11,6 +11,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate uses_of_super_in_old_style_class(Call s) { predicate uses_of_super_in_old_style_class(Call s) {
exists(Function f, ClassObject c | exists(Function f, ClassObject c |

View File

@@ -12,6 +12,7 @@
import python import python
import ClassAttributes import ClassAttributes
private import LegacyPointsTo
predicate undefined_class_attribute(SelfAttributeRead a, CheckClass c, int line, string name) { predicate undefined_class_attribute(SelfAttributeRead a, CheckClass c, int line, string name) {
name = a.getName() and name = a.getName() and

View File

@@ -13,6 +13,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate fewer_than_two_public_methods(Class cls, int methods) { predicate fewer_than_two_public_methods(Class cls, int methods) {
(methods = 0 or methods = 1) and (methods = 0 or methods = 1) and

View File

@@ -16,6 +16,7 @@
import python import python
import Expressions.CallArgs import Expressions.CallArgs
private import LegacyPointsTo
from Call call, ClassValue cls, string name, FunctionValue init from Call call, ClassValue cls, string name, FunctionValue init
where where

View File

@@ -15,6 +15,7 @@
import python import python
import Expressions.CallArgs import Expressions.CallArgs
private import LegacyPointsTo
from Call call, ClassValue cls, string too, string should, int limit, FunctionValue init from Call call, ClassValue cls, string too, string should, int limit, FunctionValue init
where where

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
from ExceptFlowNode ex, Value t, ClassValue c, ControlFlowNode origin, string what from ExceptFlowNode ex, Value t, ClassValue c, ControlFlowNode origin, string what
where where

View File

@@ -14,6 +14,7 @@
import python import python
import Raising import Raising
import Exceptions.NotImplemented import Exceptions.NotImplemented
private import LegacyPointsTo
from Raise r, ClassValue t from Raise r, ClassValue t
where where

View File

@@ -2,8 +2,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
private import semmle.python.objects.ObjectInternal
private import semmle.python.objects.ObjectAPI
/** Holds if the comparison `comp` uses `is` or `is not` (represented as `op`) to compare its `left` and `right` arguments. */ /** Holds if the comparison `comp` uses `is` or `is not` (represented as `op`) to compare its `left` and `right` arguments. */
predicate comparison_using_is(Compare comp, ControlFlowNode left, Cmpop op, ControlFlowNode right) { predicate comparison_using_is(Compare comp, ControlFlowNode left, Cmpop op, ControlFlowNode right) {

View File

@@ -13,6 +13,7 @@
import python import python
import IsComparisons import IsComparisons
private import LegacyPointsTo
from Compare comp, Cmpop op, ClassValue c from Compare comp, Cmpop op, ClassValue c
where where

View File

@@ -1,6 +1,7 @@
/** Helper functions for queries that test redundant comparisons. */ /** Helper functions for queries that test redundant comparisons. */
import python import python
private import LegacyPointsTo
/** A comparison where the left and right hand sides appear to be identical. */ /** A comparison where the left and right hand sides appear to be identical. */
class RedundantComparison extends Compare { class RedundantComparison extends Compare {

View File

@@ -16,6 +16,7 @@
import python import python
import Expressions.CallArgs import Expressions.CallArgs
private import LegacyPointsTo
from Call call, FunctionObject func, string name from Call call, FunctionObject func, string name
where where

View File

@@ -15,7 +15,6 @@
import python import python
import LegacyPointsTo import LegacyPointsTo
import semmle.python.objects.ObjectInternal
import semmle.python.strings import semmle.python.strings
predicate string_format(BinaryExpr operation, StringLiteral str, Value args, AstNode origin) { predicate string_format(BinaryExpr operation, StringLiteral str, Value args, AstNode origin) {

View File

@@ -13,6 +13,7 @@
*/ */
import python import python
private import LegacyPointsTo
import CallArgs import CallArgs
from Call call, FunctionValue func, string too, string should, int limit from Call call, FunctionValue func, string too, string should, int limit

View File

@@ -10,6 +10,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate slice_method_name(string name) { predicate slice_method_name(string name) {
name = "__getslice__" or name = "__setslice__" or name = "__delslice__" name = "__getslice__" or name = "__setslice__" or name = "__delslice__"

View File

@@ -14,6 +14,7 @@
import python import python
import Expressions.CallArgs import Expressions.CallArgs
private import LegacyPointsTo
from Call call, FunctionValue func, FunctionValue overridden, string problem from Call call, FunctionValue func, FunctionValue overridden, string problem
where where

View File

@@ -14,6 +14,7 @@
import python import python
import Expressions.CallArgs import Expressions.CallArgs
private import LegacyPointsTo
from Call call, FunctionValue func, FunctionValue overriding, string problem from Call call, FunctionValue func, FunctionValue overriding, string problem
where where

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
from ClassValue iterable, FunctionValue iter, ClassValue iterator from ClassValue iterable, FunctionValue iter, ClassValue iterator
where where

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
from FunctionValue method from FunctionValue method
where where

View File

@@ -14,7 +14,7 @@
*/ */
import python import python
import semmle.python.objects.Callables private import LegacyPointsTo
predicate meaningful_return_value(Expr val) { predicate meaningful_return_value(Expr val) {
val instanceof Name val instanceof Name

View File

@@ -13,6 +13,7 @@
import python import python
import Cyclic import Cyclic
private import LegacyPointsTo
from ModuleValue m1, ModuleValue m2, Stmt imp from ModuleValue m1, ModuleValue m2, Stmt imp
where where

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate modules_imports_itself(ImportingStmt i, ModuleValue m) { predicate modules_imports_itself(ImportingStmt i, ModuleValue m) {
i.getEnclosingModule() = m.getScope() and i.getEnclosingModule() = m.getScope() and

View File

@@ -14,6 +14,7 @@
import python import python
import Cyclic import Cyclic
private import LegacyPointsTo
// This is a potentially crashing bug if // This is a potentially crashing bug if
// 1. the imports in the whole cycle are lexically outside a def (and so executed at import time) // 1. the imports in the whole cycle are lexically outside a def (and so executed at import time)

View File

@@ -13,6 +13,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate import_star(ImportStar imp, ModuleValue exporter) { predicate import_star(ImportStar imp, ModuleValue exporter) {
exporter.importedAs(imp.getImportedModuleName()) exporter.importedAs(imp.getImportedModuleName())

View File

@@ -8,6 +8,7 @@
import python import python
import semmle.python.dependencies.TechInventory import semmle.python.dependencies.TechInventory
private import LegacyPointsTo
/* /*
* This query creates the source links for the ExternalDependencies.ql query. * This query creates the source links for the ExternalDependencies.ql query.

View File

@@ -11,6 +11,7 @@
*/ */
import python import python
private import LegacyPointsTo
from ModuleValue m, int n from ModuleValue m, int n
where n = count(ModuleValue imp | imp = m.getAnImportedModule()) where n = count(ModuleValue imp | imp = m.getAnImportedModule())

View File

@@ -11,6 +11,7 @@
*/ */
import python import python
private import LegacyPointsTo
from ModuleValue m, int n from ModuleValue m, int n
where n = count(ModuleValue imp | imp = m.getAnImportedModule+() and imp != m) where n = count(ModuleValue imp | imp = m.getAnImportedModule+() and imp != m)

View File

@@ -17,6 +17,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate needs_docstring(Scope s) { predicate needs_docstring(Scope s) {
s.isPublic() and s.isPublic() and

View File

@@ -14,7 +14,6 @@
import python import python
private import LegacyPointsTo private import LegacyPointsTo
private import semmle.python.objects.ObjectAPI
predicate assignment(AssignStmt a, Expr left, Expr right) { predicate assignment(AssignStmt a, Expr left, Expr right) {
a.getATarget() = left and a.getValue() = right a.getATarget() = left and a.getValue() = right

View File

@@ -13,6 +13,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate func_with_side_effects(Expr e) { predicate func_with_side_effects(Expr e) {
exists(string name | name = e.(Attribute).getName() or name = e.(Name).getId() | exists(string name | name = e.(Attribute).getName() or name = e.(Name).getId() |

View File

@@ -12,6 +12,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate main_eq_name(If i) { predicate main_eq_name(If i) {
exists(Name n, StringLiteral m, Compare c | exists(Name n, StringLiteral m, Compare c |

View File

@@ -13,6 +13,7 @@
*/ */
import python import python
private import LegacyPointsTo
predicate isInsideLoop(AstNode node) { predicate isInsideLoop(AstNode node) {
node.getParentNode() instanceof While node.getParentNode() instanceof While

View File

@@ -1,6 +1,7 @@
import python import python
import Loop import Loop
import semmle.python.dataflow.TaintTracking import semmle.python.dataflow.TaintTracking
private import LegacyPointsTo
/** A marker for "uninitialized". */ /** A marker for "uninitialized". */
class Uninitialized extends TaintKind { class Uninitialized extends TaintKind {

View File

@@ -13,6 +13,7 @@
import python import python
import Variables.MonkeyPatched import Variables.MonkeyPatched
private import LegacyPointsTo
/* Local variable part */ /* Local variable part */
predicate initialized_as_local(PlaceHolder use) { predicate initialized_as_local(PlaceHolder use) {

View File

@@ -14,6 +14,7 @@
import python import python
import Definition import Definition
private import LegacyPointsTo
predicate unused_parameter(FunctionValue f, LocalVariable v) { predicate unused_parameter(FunctionValue f, LocalVariable v) {
v.isParameter() and v.isParameter() and

View File

@@ -4,8 +4,7 @@
*/ */
import python import python
import semmle.python.pointsto.PointsTo private import LegacyPointsTo
import semmle.python.pointsto.PointsToContext
from int total_facts, int total_size, int depth, float efficiency from int total_facts, int total_size, int depth, float efficiency
where where

View File

@@ -4,8 +4,7 @@
*/ */
import python import python
import semmle.python.pointsto.PointsTo private import LegacyPointsTo
import semmle.python.pointsto.PointsToContext
from int total_facts, int total_size, int depth, float efficiency from int total_facts, int total_size, int depth, float efficiency
where where

View File

@@ -4,8 +4,7 @@
*/ */
import python import python
import semmle.python.pointsto.PointsTo private import LegacyPointsTo
import semmle.python.pointsto.PointsToContext
from int total_facts, int total_size, int depth, float efficiency from int total_facts, int total_size, int depth, float efficiency
where where

View File

@@ -4,8 +4,7 @@
*/ */
import python import python
import semmle.python.pointsto.PointsTo private import LegacyPointsTo
import semmle.python.pointsto.PointsToContext
int depth(ControlFlowNode f, Object value, ClassObject cls) { int depth(ControlFlowNode f, Object value, ClassObject cls) {
exists(PointsToContext ctx | exists(PointsToContext ctx |

View File

@@ -3,7 +3,7 @@
*/ */
import python import python
import semmle.python.pointsto.PointsTo private import LegacyPointsTo
private newtype TSymbol = private newtype TSymbol =
TModule(Module m) or TModule(Module m) or

View File

@@ -1,5 +1,5 @@
import python import python
import semmle.python.pointsto.PointsTo private import LegacyPointsTo
from ClassValue cls, string reason from ClassValue cls, string reason
where Types::failedInference(cls, reason) where Types::failedInference(cls, reason)

View File

@@ -8,6 +8,7 @@
*/ */
import python import python
private import LegacyPointsTo
from Class cls, string reason from Class cls, string reason
where exists(ClassObject c | c.getPyClass() = cls | c.failedInference(reason)) where exists(ClassObject c | c.getPyClass() = cls | c.failedInference(reason))

View File

@@ -5,6 +5,7 @@
import python import python
import meta.MetaMetrics import meta.MetaMetrics
private import LegacyPointsTo
newtype TTarget = newtype TTarget =
TFunction(Function func) or TFunction(Function func) or