Python: small refactor

This commit is contained in:
Rasmus Lerchedahl Petersen
2021-01-26 21:17:07 +01:00
parent d3e0e84c37
commit 9b13834d28
3 changed files with 11 additions and 3 deletions

View File

@@ -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__" }

View File

@@ -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. */

View File

@@ -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 */