Function Call AST Python Object
The FunctionCall
object matches a Python function, module or object call.
The astType
value for this node is functioncall
.
Code Pattern
This object captures the following code pattern.
my_function(arg1, arg2)
Attributes
moduleOrObject
(typeAstString
): the prefix of the function call. If we do a callfoo.bar
, themoduleOrObject
value isfoo
functionName
(typeAstString
): the name of the functionarguments
(typeFunctionCallArguments
): the list of arguments
Examples of rules
- python-security/avoid-random
- python-security/insecure-hash-functions
- python-security/subprocess-shell-true
Usage
const functionCall = ...
// Get the function name
if (functionCall.functionName && functionCall.functionName.value) {
const functionName = functionCall.functionName.value;
}
// Get the list of all the arguments names
if (functionCall.arguments && functionCall.arguments.values) {
const argumentsNames = functionCall.arguments.values.filter(a => a.name && a.name.value).map(a => a.name.value);
}
Data Example
This is what the representation of the data looks for a function call such as
module_name.my_function(foo = 42)
{
"moduleOrObject": {
"astType": "string",
"start": {
"line": 1,
"col": 2
},
"end": {
"line": 1,
"col": 2
},
"value": "module_name"
},
"functionName": {
"astType": "string",
"start": {
"line": 1,
"col": 4
},
"end": {
"line": 1,
"col": 10
},
"value": "my_function"
},
"arguments": {
"start": {
"line": 1,
"col": 4
},
"end": {
"line": 1,
"col": 10
},
"values": [
{
"start": {
"line": 1,
"col": 4
},
"end": {
"line": 1,
"col": 10
},
"name": {
"astType": "string",
"start": {
"line": 1,
"col": 2
},
"end": {
"line": 1,
"col": 2
},
"value": "foo"
},
"value": {
"astType": "string",
"start": {
"line": 1,
"col": 2
},
"end": {
"line": 1,
"col": 2
},
"value": "42"
}
}
]
}
}