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
private import semmle.python.pointsto.PointsTo
private import LegacyPointsTo
/** A helper class for UndefinedClassAttribute.ql and MaybeUndefinedClassAttribute.ql */
class CheckClass extends ClassObject {

View File

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

View File

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

View File

@@ -12,6 +12,7 @@
*/
import python
private import LegacyPointsTo
ClassObject left_base(ClassObject type, ClassObject base) {
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 ClassAttributes
private import LegacyPointsTo
predicate guarded_by_other_attribute(SelfAttributeRead a, CheckClass c) {
c.sometimesDefines(a.getName()) and

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,8 +2,6 @@
import python
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. */
predicate comparison_using_is(Compare comp, ControlFlowNode left, Cmpop op, ControlFlowNode right) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -14,6 +14,7 @@
import python
import Cyclic
private import LegacyPointsTo
// 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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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