FunctionCall
Abstract representation of a function invocation, e.g. in Python: def f(): g() # FunctionCall
Inherits from
Properties
args
Returns list of args passed into the function invocation
extended
Returns a SymbolGroup of all extended nodes. This allows a common edit interface for all of extended nodes.
extended_source
Text representation of all its extended nodes
file
The file object that this Editable instance belongs to
filepath
The file path of the file that this Editable instance belongs to
full_name
The full name including the object lookup (if applicable).
Examples: For a.b, the full name is a.b
function_calls
Returns all contained function calls. Useful for renaming function invocations etc.
function_definitions
Returns the Functions that could be called. Good for viewing parameter names and types + return types.
is_awaited
Returns True if the function call is awaited
name
The name of the object excluding whichever namespace precedes it, as a string.
Examples: For a.b, the name is b
predecessor
Returns the previous function call in a function call chain
resolved_value
If the expression is a resolvable value, returns the last assigned expression value. Else, returns itself.
Example: a = 1 b = a foo(b)
If we call resolve_value on b, it returns 1.
source
Text representation of this FunctionCall
variable_usages
Returns Editables for all TreeSitter node instances of variable usages. (Excludes: property identifiers and argument keywords) This is useful for renaming variables locally and analyzing variable usages.
Methods
asyncify
Converts the function call to an async function call
commit
Commit just this node
convert_args_to_kwargs
Exclude is the number of leading args to exclude from the conversion this is the only control over excluding args we allow the consumer b/c positional args must come before keyword args
edit
Replace the source of this Editable
with new_src
.
When fix_indentation
is True, the indentation of new_src
will be adjusted to match the current text’s indentation.
find
Returns a list of all substring match in strings_to_match
, similar to python’s str.find(..)
Args: exact: Only match individual nodes which exactly match the query
find_string_literals
Returns a list of all editable substrings within string literals that match strings_to_match
flag
Adds a comment so the developer can see this Editable
from_usage
Creates a FunctionCall object from an Editable instance that represents a function call. Useful to pair with Editable API when searching a text that represents a function call.
get_arg_by_index
Returns the Argument with the given index. Returns None if not found.
get_arg_by_parameter_name
Returns the argument with the given name. Returns None if not found.
get_function_definition
Returns the Function that is being called. Good for viewing parameter names and types + return types.
get_name
Returns the Name of the object, as a Name
(editable)
get_parent_function
Returns the parent block of the function call
get_variable_usages
Returns Editables for all TreeSitter nodes corresponding to instances of variable usage that matches the given variable name.
(Excludes: property identifiers and argument keywords)
fuzzy_match
allows for partial matching of variable names and effectively does var_name in usage.name
insert_after
Inserts new_src after this node
insert_before
Inserts new_src before this node
remove
Deletes this Node, and optionally its related extended nodes (e.g. decorators, comments, etc.)
rename
Sets the name of the object as well its usages
replace
Search and replace an instance of substring
within this node’s source. Similar to python’s string.replace(..)
Throws ValueError if there are more than one occurrence of substring in this node’s source.
Arguments:
old: the occurrences of this string to replace
new: the string to replace with
count: the max number of occurrences to replace. Default value: -1 (replace all)
is_regex: whether old
is a regex pattern. Default value: False
Returns:
The total count of old
occurrences replaced.
search
Returns a list of all regex match of regex_pattern
, similar to python’s re.search(…)
When include_strings
is False, the search will exclude the contents of string literals from the search.
When include_comments
is False, the search will exclude the contents of comments from the search.
set_kwarg
Set the keyword argument to a new value Args: name: Name of parameter to set value: Value to set it as create_on_missing: Add a new argument if the argument is not set in the function call override_existing: Override the existing kwarg if it is present
set_name
Sets the name of the object
Was this page helpful?