Inherits from

Expression, HasName, Editable

Properties


args

Returns a list of arguments passed into the function invocation.

The args property provides access to all arguments, both positional and keyword, that are passed to the function call.

Args: None

Returns: Collection[Argument, Self]: A collection containing the function’s arguments.

def args(self) -> Collection[Argument, Self]:
    ...

extended

Returns a SymbolGroup of all extended nodes associated with this element.

Creates a SymbolGroup that provides a common interface for editing all extended nodes, such as decorators, modifiers, and comments associated with the element.

Args: None

Returns: SymbolGroup: A group containing this node and its extended nodes that allows batch modification through a common interface.

def extended(self) -> SymbolGroup:
    ...

extended_source

Returns the source text representation of all extended nodes.

Gets the source text of all extended nodes combined. This property allows reading the source text of all extended nodes (e.g. decorators, export statements) associated with this node.

Returns: str: The combined source text of all extended nodes.

def extended_source(self) -> str:
    ...

file

The file object that this Editable instance belongs to.

Retrieves or caches the file object associated with this Editable instance.

Returns: File: The File object containing this Editable instance.

def file(self) -> SourceFile:
    ...

filepath

The file path of the file that this Editable instance belongs to.

Returns a string representing the absolute file path of the File that contains this Editable instance.

Returns: str: The absolute file path.

def filepath(self) -> str:
    ...

full_name

Returns the full name of the object, including the namespace path.

Returns the complete qualified name of an object, including any parent class or namespace paths. For class methods, this returns the parent class’s full name followed by the method name. For chained attributes (e.g., ‘a.b’), this returns the full chained name.

Args: None

Returns: str | None: The complete qualified name of the object. Returns None if no name is available. For class methods, returns ‘ParentClass.method_name’. For chained attributes, returns the full chain (e.g., ‘a.b’). For simple names, returns just the name.

def full_name(self) -> str | None:
    ...

function_calls

Returns a list of all function calls contained within this function call.

This method traverses through all arguments and the function name node to find any nested function calls. For example, if a function call has arguments that are themselves function calls, these will be included in the returned list.

Returns: list[FunctionCall]: A list of FunctionCall instances contained within this function call, including the call itself. Sorted by their appearance in the code.

def function_calls(self) -> list[FunctionCall]:
    ...

function_definition

Returns the resolved function definition that is being called.

This method returns the function definition associated with this function call. This is useful for accessing parameter names, parameter types, and return types of the called function.

Returns: Callable | None: The resolved function definition, or None if no definition is found.

def function_definition(self) -> Callable | None:
    ...

function_definitions

Returns a list of callable objects that could potentially be the target of this function call.

Finds and returns all possible functions that this call could be invoking based on name resolution. This is useful for analyzing parameter names, parameter types, and return types of the potential target functions.

Returns: list[Callable]: A list of Callable objects representing the possible function definitions that this call could be invoking.

def function_definitions(self) -> list[Callable]:
    ...

is_awaited

Returns whether the function call is awaited with an ‘await’ keyword.

Checks if this function call appears within an await expression by traversing up the parent nodes.

Returns: bool: True if the function call is within an await expression, False otherwise.

def is_awaited(self) -> bool:
    ...

name

Retrieves the name of the object excluding any namespace prefixes.

Returns the “base” name of the object without any namespace or module prefix. For instance, for an object ‘a.b’, this method returns ‘b’.

Returns: str | None: The base name of the object as a string, or None if there is no associated name node.

def name(self) -> str | None:
    ...

parent_function

Retrieves the parent function of the current function call.

Returns the Function object that contains this function call, useful for understanding the context in which a function call is made.

Returns: Function | None: The parent Function object containing this function call, or None if not found or if the function call is not within a function.

def parent_function(self) -> Function | None:
    ...

predecessor

Returns the previous function call in a function call chain.

Returns the previous function call in a function call chain. This method is useful for traversing function call chains to analyze or modify sequences of chained function calls.

Returns: FunctionCall[Parent] | None: The previous function call in the chain, or None if there is no predecessor or if the predecessor is not a function call.

def predecessor(self) -> FunctionCall[Parent] | None:
    ...

resolved_value

Returns the resolved value of an Expression.

Returns the last assigned expression value if the expression is resolvable, otherwise returns itself. For example, if ‘b = a’ where ‘a = 1’, resolving ‘b’ returns 1.

Returns: Union[Expression, list[Expression]]: The resolved expression value(s). Returns a single Expression if there is only one resolved value, or a list of Expressions if there are multiple resolved values. Returns self if the expression is not resolvable or has no resolved types.

def resolved_value(self) -> Expression | list[Expression]:
    ...

source

Gets the source code representation of this FunctionCall.

Returns the textual representation of the function call. For chained function calls (e.g., a().b()), it returns only the current function call’s source code by removing the predecessor’s source.

Args: None

Returns: str: The source code representation of this function call. For chained calls, returns only the current function call’s portion of the chain.

def source(self) -> str:
    ...

variable_usages

Returns Editables for all TreeSitter node instances of variable usages within this node’s scope.

This method finds all variable identifier nodes in the TreeSitter AST, excluding:

  • Function names in function calls
  • Import names in import statements
  • Property access identifiers (except the base object)
  • Keyword argument names (in Python and TypeScript)

This is useful for variable renaming and usage analysis within a scope.

Returns: list[Editable]: A list of Editable nodes representing variable usages. Each Editable corresponds to a TreeSitter node instance where the variable is referenced.

def variable_usages(self) -> list[Editable]:
    ...

Methods


asyncify

Converts the function call to an async function call by wrapping it with ‘await’.

This method adds ‘await’ syntax to a function call if it is not already awaited. It wraps the function call in parentheses and prefixes it with ‘await’.

Args: None

Returns: None

def asyncify(self) -> None:
    ...

commit

Commits any pending transactions for the current node to the codebase.

Commits only the transactions that affect the file this node belongs to. This is useful when you want to commit changes made to a specific node without committing all pending transactions in the codebase.

Args: None

Returns: None

def commit(self) -> None:
    ...

convert_args_to_kwargs

Converts positional arguments in a function call to keyword arguments.

This method converts positional arguments to keyword arguments, excluding any leading arguments specified by the exclude parameter. This is useful when refactoring function calls to be more explicit and self-documenting.

Args: exclude (int): Number of leading positional arguments to exclude from conversion. Defaults to 0.

Returns: None

Note:

  • Skips conversion if the argument is already named
  • Skips arguments within the exclude range
  • Skips unpacked arguments (e.g. **kwargs)
  • Stops converting if it encounters a named argument that would conflict with an existing one
  • Requires the function definition to be resolvable and have parameters
def convert_args_to_kwargs(self, exclude: int = 0) -> None:
    ...

edit

Replace the source of this Editable with new_src.

Replaces the text representation of this Editable instance with new text content. The method handles indentation adjustments and transaction management.

Args: new_src (str): The new source text to replace the current text with. fix_indentation (bool): If True, adjusts the indentation of new_src to match the current text’s indentation level. Defaults to False. priority (int): The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0. dedupe (bool): If True, deduplicates identical transactions. Defaults to True.

Returns: None

def edit(self, new_src: str, fix_indentation: bool = False, priority: int = 0, dedupe: bool = True) -> None:
    ...

find

Find and return matching nodes or substrings within an Editable instance.

This method searches through the extended_nodes of the Editable instance and returns all nodes or substrings that match the given search criteria.

Args: strings_to_match (Union[list[str], str]): One or more strings to search for. exact (bool): If True, only return nodes whose source exactly matches one of the strings_to_match. If False, return nodes that contain any of the strings_to_match as substrings. Defaults to False.

Returns: list[Editable]: A list of Editable instances that match the search criteria.

def find(self, strings_to_match: list[str] | str, *, exact: bool = False) -> list[Editable]:
    ...

find_string_literals

Returns a list of string literals within this node’s source that match any of the given strings.

Args: strings_to_match (list[str]): A list of strings to search for in string literals. fuzzy_match (bool): If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False.

Returns: list[Editable]: A list of Editable objects representing the matching string literals.

def find_string_literals(self, strings_to_match: list[str], fuzzy_match: bool = False) -> list[Editable]:
    ...

flag

Adds a visual flag comment to the end of this Editable’s source text.

Flags this Editable by appending a comment with emoji flags at the end of its source text. This is useful for visually highlighting specific nodes in the source code during development and debugging.

Returns: None

def flag(self, **kwargs: Unpack[FlagKwargs]) -> CodeFlag[Self]:
    ...

from_usage

Creates a FunctionCall object from an Editable instance that represents a function call.

Takes an Editable node that potentially represents a function call and creates a FunctionCall object from it. Useful when working with search results from the Editable API that may contain function calls.

Args: node (Editable[Parent]): The Editable node that potentially represents a function call. parent (Parent | None): The parent node for the new FunctionCall. If None, uses the parent from the input node.

Returns: Self | None: A new FunctionCall object if the input node represents a function call, None otherwise.

def from_usage(cls, node: Editable[Parent], parent: Parent | None = None) -> Self | None:
    ...

get_arg_by_index

Returns the Argument with the given index from the function call’s argument list.

Args: arg_idx (int): The index of the argument to retrieve.

Returns: Argument | None: The Argument object at the specified index, or None if the index is out of bounds.

def get_arg_by_index(self, arg_idx: int) -> Argument | None:
    ...

get_arg_by_parameter_name

Returns an argument by its parameter name.

Searches through the arguments of a function call to find an argument that matches a specified parameter name. This first checks for named arguments (kwargs) that match the parameter name directly, then checks for positional arguments by resolving their corresponding parameter names.

Args: param_name (str): The name of the parameter to search for.

Returns: Argument | None: The matching argument if found, None otherwise.

def get_arg_by_parameter_name(self, param_name: str) -> Argument | None:
    ...

get_name

Returns the Name node of the object.

Retrieves the name node of the object which can be used for modification operations.

Returns: Name | ChainedAttribute | None: The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name.

def get_name(self) -> Name | ChainedAttribute | None:
    ...

get_variable_usages

Returns Editables for all TreeSitter nodes corresponding to instances of variable usage that matches the given variable name.

Retrieves a list of variable usages that match a specified name, with an option for fuzzy matching. By default, excludes property identifiers and argument keywords.

Args: var_name (str): The variable name to search for. fuzzy_match (bool): If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False.

Returns: list[Editable]: List of Editable objects representing variable usage nodes matching the given name.

def get_variable_usages(self, var_name: str, fuzzy_match: bool = False) -> list[Editable]:
    ...

insert_after

Inserts code after this node.

Args: new_src (str): The source code to insert after this node. fix_indentation (bool, optional): Whether to adjust the indentation of new_src to match the current node. Defaults to False. newline (bool, optional): Whether to add a newline before the new_src. Defaults to True. priority (int, optional): Priority of the insertion transaction. Defaults to 0. dedupe (bool, optional): Whether to deduplicate identical transactions. Defaults to True.

Returns: None

def insert_after(self, new_src: str, fix_indentation: bool = False, newline: bool = True, priority: int = 0, dedupe: bool = True) -> None:
    ...

insert_before

Inserts text before this node’s source with optional indentation and newline handling.

This method inserts the provided text before the current node’s source code. It can automatically handle indentation and newline placement.

Args: new_src (str): The text to insert before this node. fix_indentation (bool): Whether to fix the indentation of new_src to match the current node. Defaults to False. newline (bool): Whether to add a newline after new_src. Defaults to True. priority (int): Transaction priority for managing multiple edits. Defaults to 0. dedupe (bool): Whether to deduplicate identical transactions. Defaults to True.

Returns: None

def insert_before(self, new_src: str, fix_indentation: bool = False, newline: bool = True, priority: int = 0, dedupe: bool = True) -> None:
    ...

reduce_condition

Reduces an editable to the following condition

def reduce_condition(self, bool_condition: bool, node: Editable | None = None) -> None:
    ...

remove

Removes a node and optionally its related extended nodes.

This method removes a FunctionCall node from the codebase. If the node is part of an expression statement, it removes the entire expression statement. Otherwise, it performs a standard node removal.

Args: delete_formatting (bool, optional): Whether to delete associated formatting nodes. Defaults to True. priority (int, optional): Priority level for the removal operation. Defaults to 0. dedupe (bool, optional): Whether to deduplicate identical removals. Defaults to True.

Returns: None

def remove(self, delete_formatting: bool = True, priority: int = 0, dedupe: bool = True) -> None:
    ...

rename

Sets the name of an object and updates all its usages throughout the codebase.

This method renames a symbol (like a class, function, variable) and automatically updates all references to this symbol throughout the codebase, ensuring consistency across all usages.

Args: name (str): The new name to assign to the object.

Returns: None

def rename(self, name: str) -> None:
    ...

replace

Search and replace occurrences of text within this node’s source and its extended nodes.

This method performs string replacement similar to Python’s string.replace(), with support for regex patterns. It operates on both the main node and any extended nodes (e.g. decorators, exports).

Args: old (str): The text or pattern to search for. new (str): The text to replace matches with. count (int, optional): Maximum number of replacements to make. Defaults to -1 (replace all). is_regex (bool, optional): Whether to treat ‘old’ as a regex pattern. Defaults to False. priority (int, optional): Priority of the replacement operation. Defaults to 0.

Returns: int: The total number of replacements made.

Raises: ValueError: If there are multiple occurrences of the substring in a node’s source.

def replace(self, old: str, new: str, count: int = -1, is_regex: bool = False, priority: int = 0) -> int:
    ...

Returns a list of all regex match of regex_pattern, similar to python’s re.search().

Searches for matches of a regular expression pattern within the text of this node and its extended nodes.

Args: regex_pattern (str): The regular expression pattern to search for. include_strings (bool): When False, excludes the contents of string literals from the search. Defaults to True. include_comments (bool): When False, excludes the contents of comments from the search. Defaults to True.

Returns: list[Editable]: A list of Editable objects corresponding to the matches found.

def search(self, regex_pattern: str, include_strings: bool = True, include_comments: bool = True) -> list[Editable]:
    ...

set_kwarg

Set a keyword argument in a function call.

Sets or modifies a keyword argument in the function call. Can create new arguments or modify existing ones based on configuration.

Args: name (str): The name of the parameter/argument to set. value (str): The value to set the argument to. create_on_missing (bool, optional): If True, creates a new keyword argument if it doesn’t exist. Defaults to True. override_existing (bool, optional): If True, modifies the value of existing argument. Defaults to True.

Returns: None

Raises: None

def set_kwarg(self, name: str, value: str, *, create_on_missing: bool = True, override_existing: bool = True) -> None:
    ...

set_name

Sets the name of a code element.

Modifies the name of the object’s underlying name node. Works with both simple names and chained attributes (e.g., ‘a.b’).

Args: name (str): The new name to set for the object.

Returns: None

def set_name(self, name: str) -> None:
    ...