mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
Python: small refactor
This commit is contained in:
@@ -39,6 +39,12 @@ class Function extends Function_, Scope, AstNode {
|
||||
exists(YieldFrom y | y.getScope() = this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this is a lambda.
|
||||
* We detect this by comparing its name to the one the extractor gives to lambdas.
|
||||
*/
|
||||
predicate isLambda() { this.getName() = "lambda" }
|
||||
|
||||
/** Whether this function is declared in a class and is named `__init__` */
|
||||
predicate isInitMethod() { this.isMethod() and this.getName() = "__init__" }
|
||||
|
||||
|
||||
@@ -499,12 +499,11 @@ import ArgumentPassing
|
||||
newtype TDataFlowCallable =
|
||||
TCallableValue(CallableValue callable) {
|
||||
callable instanceof FunctionValue and
|
||||
// TODO: push into FunctionValue
|
||||
not callable.(FunctionValue).getOrigin().getNode() instanceof Lambda
|
||||
not callable.(FunctionValue).isLambda()
|
||||
or
|
||||
callable instanceof ClassValue
|
||||
} or
|
||||
TLambda(Function lambda) { lambda.getName() = "lambda" } or
|
||||
TLambda(Function lambda) { lambda.isLambda() } or
|
||||
TModule(Module m)
|
||||
|
||||
/** Represents a callable. */
|
||||
|
||||
@@ -720,6 +720,9 @@ abstract class FunctionValue extends CallableValue {
|
||||
|
||||
/** Gets a class that this function may return */
|
||||
abstract ClassValue getAnInferredReturnType();
|
||||
|
||||
/** Wheter this is a lambda function */
|
||||
predicate isLambda() { this.getOrigin().getNode() instanceof Lambda }
|
||||
}
|
||||
|
||||
/** Class representing Python functions */
|
||||
|
||||
Reference in New Issue
Block a user