Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b13834

Browse files
committed
Python: small refactor
1 parent d3e0e84 commit 9b13834

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

python/ql/src/semmle/python/Function.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class Function extends Function_, Scope, AstNode {
3939
exists(YieldFrom y | y.getScope() = this)
4040
}
4141

42+
/**
43+
* Whether this is a lambda.
44+
* We detect this by comparing its name to the one the extractor gives to lambdas.
45+
*/
46+
predicate isLambda() { this.getName() = "lambda" }
47+
4248
/** Whether this function is declared in a class and is named `__init__` */
4349
predicate isInitMethod() { this.isMethod() and this.getName() = "__init__" }
4450

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,11 @@ import ArgumentPassing
499499
newtype TDataFlowCallable =
500500
TCallableValue(CallableValue callable) {
501501
callable instanceof FunctionValue and
502-
// TODO: push into FunctionValue
503-
not callable.(FunctionValue).getOrigin().getNode() instanceof Lambda
502+
not callable.(FunctionValue).isLambda()
504503
or
505504
callable instanceof ClassValue
506505
} or
507-
TLambda(Function lambda) { lambda.getName() = "lambda" } or
506+
TLambda(Function lambda) { lambda.isLambda() } or
508507
TModule(Module m)
509508

510509
/** Represents a callable. */

python/ql/src/semmle/python/objects/ObjectAPI.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,9 @@ abstract class FunctionValue extends CallableValue {
720720

721721
/** Gets a class that this function may return */
722722
abstract ClassValue getAnInferredReturnType();
723+
724+
/** Wheter this is a lambda function */
725+
predicate isLambda() { this.getOrigin().getNode() instanceof Lambda }
723726
}
724727

725728
/** Class representing Python functions */

0 commit comments

Comments
 (0)