Abstract representation of a Function.
HasBlock, Callable, Symbol, Editable, Expression, Usable, Importable, HasName
Returns all call sites (invocations) of this callable in the codebase.
The block of code associated with the code object.
Returns the comment group associated with the symbol, if any.
Returns list of all decorators on this Symbol.
Retrieves the docstring of the expression.
Returns a SymbolGroup of all extended nodes associated with this element.
Returns a list of Editable nodes associated with this symbol, including extended symbols.
str
Returns the source text representation of all extended nodes.
The file object that this Editable instance belongs to.
str
The file path of the file that this Editable instance belongs to.
str | None
Returns the full name of the object, including the namespace path.
Gets all function calls within the function and its parameters.
str
Returns the signature of the function as a string.
str | None
Gets the inferred type of the function from the language's native language engine / compiler.
Returns the inline comment group associated with the symbol, if any.
bool
Returns True if the function is asynchronous.
bool
Determines if the current function is a constructor method.
bool
Check if the symbol has decorators.
bool
Returns True if function is a magic method.
bool
Returns whether the function is a method of a class.
bool
Indicates whether the function is an overloaded function in a multi-function definition.
bool
Determines if a function has a private access modifier.
bool
Returns whether this function is a property.
str | None
Retrieves the base name of the object without namespace prefixes.
Returns a list of nested functions defined within this function's code block.
Retrieves all parameters of a callable symbol.
The parent node of this Editable instance.
Find the class this node is contained in
Find the function this node is contained in
Find the statement this node is contained in
Returns the resolved type of an Expression.
Returns a list of all return statements within this function's body.
The type of value returned by the callable, or a placeholder.
str
Returns the source code of the symbol.
The type of symbol, set to SymbolType.Function.
Returns Editables for all TreeSitter node instances of variable usages within this node's
Adds a comment to the symbol.
str
The comment text to add.
None
Adds a decorator to a function or method.
str
The decorator to add, including the '@' symbol.
bool, optional
If True, skips adding if the decorator exists.
bool
True if the decorator was added, False if skipped.
Insert a keyword in the appropriate place before this symbol if it doesn’t already exist.
str
The keyword to be inserted. Must be a valid keyword in the language context.
None
Adds statements to the end of a function body.
str
The lines of code to be added at the end of the function body.
None
Find all ancestors of the node of the given type. Does not return itself
Modifies the function to be asynchronous.
None
Returns a list of symbols that this symbol depends on.
The types of dependencies to search for. Defaults to UsageType.DIRECT.
int | None
Maximum depth to traverse in the dependency graph. If provided, will recursively collect
Replace the source of this node with new_src.
str
The new source code to replace the current source with.
bool
If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False.
int
The priority of this edit. Higher priority edits take precedence. Defaults to 0.
bool
If True, prevents duplicate edits. Defaults to True.
None
Find and return matching nodes or substrings within an Editable instance.
Union[list[str], str]
One or more strings to search for.
bool
If True, only return nodes whose source exactly matches one of the strings_to_match.
A list of Editable instances that match the search criteria.
Returns a list of string literals within this node’s source that match any of the given
list[str]
A list of strings to search for in string literals.
bool
If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False.
Adds a visual flag comment to the end of this Editable’s source text.
Returns the name node of the object.
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.
Gets a specific parameter from the callable’s parameters list by name.
str
The name of the parameter to retrieve.
The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters.
Returns the parameter at the given index.
int
The index of the parameter to retrieve.
The parameter at the specified index, or None if the parameter list is empty or the index does not exist.
Retrieves a parameter from the callable by its type.
The type to search for.
The parameter with the specified type, or None if no parameter is found or if the callable has no parameters.
Returns Editables for all TreeSitter nodes corresponding to instances of variable usage
str
The variable name to search for.
bool
If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False.
Inserts code after this node.
str
The source code to insert after this node.
bool, optional
Whether to adjust the indentation of new_src to match the current node. Defaults to False.
bool, optional
Whether to add a newline before the new_src. Defaults to True.
int, optional
Priority of the insertion transaction. Defaults to 0.
bool, optional
Whether to deduplicate identical transactions. Defaults to True.
None
Inserts text before the current symbol node in the Abstract Syntax Tree.
str
The source code text to insert.
bool
Whether to adjust the indentation of new_src to match current text. Defaults to False.
bool
Whether to add a newline after insertion. Defaults to True.
int
Priority of this edit operation. Higher priority edits are applied first. Defaults to 0.
bool
Whether to remove duplicate insertions. Defaults to True.
bool
Whether to insert before extended nodes like comments and decorators. Defaults to True.
None
Inserts lines of code into the function body at the specified index.
str
The code lines to insert into the function body.
int, optional
The position in the function body where the lines should be inserted. Defaults to 0.
None
Checks if this node is a descendant of the given editable instance in the AST.
bool
Check if this node is contained another node of the given class
bool
Moves the given symbol to a new file and updates its imports and references.
The destination file to move the symbol to.
bool
If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True.
str
The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'.
None
Find the first ancestor of the node of the given type. Does not return itself
Find the first ancestor of the node of the given type. Does not return itself
Prepends the provided code to the beginning of the function body.
str
The code to be prepended to the function body.
None
Reduces an editable to the following condition
None
Deletes this Node and its related extended nodes (e.g. decorators, comments).
bool
Whether to delete surrounding whitespace and formatting. Defaults to True.
int
Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0.
bool
Whether to deduplicate removal transactions at the same location. Defaults to True.
None
Renames a symbol and updates all its references in the codebase.
str
The new name for the symbol.
int
Priority of the edit operation. Defaults to 0.
tuple[NodeId, NodeId]
A tuple containing the file node ID and the new node ID of the renamed symbol.
Renames a local variable and all its usages within a function body.
str
The current name of the local variable to be renamed.
str
The new name to give to the local variable.
bool, optional
If True, matches variable names that contain old_var_name. Defaults to False.
None
The method modifies the AST in place.
Search and replace occurrences of text within this node’s source and its extended nodes.
str
The text or pattern to search for.
str
The text to replace matches with.
int, optional
Maximum number of replacements to make. Defaults to -1 (replace all).
bool, optional
Whether to treat 'old' as a regex pattern. Defaults to False.
int, optional
Priority of the replacement operation. Defaults to 0.
int
The total number of replacements made.
Returns a list of all regex match of regex_pattern
, similar to python’s re.search().
str
The regular expression pattern to search for.
bool
When False, excludes the contents of string literals from the search. Defaults to True.
bool
When False, excludes the contents of comments from the search. Defaults to True.
A list of Editable objects corresponding to the matches found.
Sets a comment to the symbol.
str
The comment text to set.
None
Sets or updates the docstring for the current entity.
str
The new docstring content to set.
None
This method doesn't return anything.
Sets an inline comment to the symbol.
str
The text of the inline comment to be added or updated.
None
Sets the name of a code element.
str
The new name to set for the object.
None
Sets the return type annotation for the function.
str
The new return type annotation to be set. Use an empty string to remove
None
Returns a list of symbols that use or import the exportable object.
The types of usages to search for. Defaults to any.
Returns a list of usages of the exportable object.
Specifies which types of usages to include in the results. Default is any usages.
A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse.
Abstract representation of a Function.
HasBlock, Callable, Symbol, Editable, Expression, Usable, Importable, HasName
Returns all call sites (invocations) of this callable in the codebase.
The block of code associated with the code object.
Returns the comment group associated with the symbol, if any.
Returns list of all decorators on this Symbol.
Retrieves the docstring of the expression.
Returns a SymbolGroup of all extended nodes associated with this element.
Returns a list of Editable nodes associated with this symbol, including extended symbols.
str
Returns the source text representation of all extended nodes.
The file object that this Editable instance belongs to.
str
The file path of the file that this Editable instance belongs to.
str | None
Returns the full name of the object, including the namespace path.
Gets all function calls within the function and its parameters.
str
Returns the signature of the function as a string.
str | None
Gets the inferred type of the function from the language's native language engine / compiler.
Returns the inline comment group associated with the symbol, if any.
bool
Returns True if the function is asynchronous.
bool
Determines if the current function is a constructor method.
bool
Check if the symbol has decorators.
bool
Returns True if function is a magic method.
bool
Returns whether the function is a method of a class.
bool
Indicates whether the function is an overloaded function in a multi-function definition.
bool
Determines if a function has a private access modifier.
bool
Returns whether this function is a property.
str | None
Retrieves the base name of the object without namespace prefixes.
Returns a list of nested functions defined within this function's code block.
Retrieves all parameters of a callable symbol.
The parent node of this Editable instance.
Find the class this node is contained in
Find the function this node is contained in
Find the statement this node is contained in
Returns the resolved type of an Expression.
Returns a list of all return statements within this function's body.
The type of value returned by the callable, or a placeholder.
str
Returns the source code of the symbol.
The type of symbol, set to SymbolType.Function.
Returns Editables for all TreeSitter node instances of variable usages within this node's
Adds a comment to the symbol.
str
The comment text to add.
None
Adds a decorator to a function or method.
str
The decorator to add, including the '@' symbol.
bool, optional
If True, skips adding if the decorator exists.
bool
True if the decorator was added, False if skipped.
Insert a keyword in the appropriate place before this symbol if it doesn’t already exist.
str
The keyword to be inserted. Must be a valid keyword in the language context.
None
Adds statements to the end of a function body.
str
The lines of code to be added at the end of the function body.
None
Find all ancestors of the node of the given type. Does not return itself
Modifies the function to be asynchronous.
None
Returns a list of symbols that this symbol depends on.
The types of dependencies to search for. Defaults to UsageType.DIRECT.
int | None
Maximum depth to traverse in the dependency graph. If provided, will recursively collect
Replace the source of this node with new_src.
str
The new source code to replace the current source with.
bool
If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False.
int
The priority of this edit. Higher priority edits take precedence. Defaults to 0.
bool
If True, prevents duplicate edits. Defaults to True.
None
Find and return matching nodes or substrings within an Editable instance.
Union[list[str], str]
One or more strings to search for.
bool
If True, only return nodes whose source exactly matches one of the strings_to_match.
A list of Editable instances that match the search criteria.
Returns a list of string literals within this node’s source that match any of the given
list[str]
A list of strings to search for in string literals.
bool
If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False.
Adds a visual flag comment to the end of this Editable’s source text.
Returns the name node of the object.
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.
Gets a specific parameter from the callable’s parameters list by name.
str
The name of the parameter to retrieve.
The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters.
Returns the parameter at the given index.
int
The index of the parameter to retrieve.
The parameter at the specified index, or None if the parameter list is empty or the index does not exist.
Retrieves a parameter from the callable by its type.
The type to search for.
The parameter with the specified type, or None if no parameter is found or if the callable has no parameters.
Returns Editables for all TreeSitter nodes corresponding to instances of variable usage
str
The variable name to search for.
bool
If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False.
Inserts code after this node.
str
The source code to insert after this node.
bool, optional
Whether to adjust the indentation of new_src to match the current node. Defaults to False.
bool, optional
Whether to add a newline before the new_src. Defaults to True.
int, optional
Priority of the insertion transaction. Defaults to 0.
bool, optional
Whether to deduplicate identical transactions. Defaults to True.
None
Inserts text before the current symbol node in the Abstract Syntax Tree.
str
The source code text to insert.
bool
Whether to adjust the indentation of new_src to match current text. Defaults to False.
bool
Whether to add a newline after insertion. Defaults to True.
int
Priority of this edit operation. Higher priority edits are applied first. Defaults to 0.
bool
Whether to remove duplicate insertions. Defaults to True.
bool
Whether to insert before extended nodes like comments and decorators. Defaults to True.
None
Inserts lines of code into the function body at the specified index.
str
The code lines to insert into the function body.
int, optional
The position in the function body where the lines should be inserted. Defaults to 0.
None
Checks if this node is a descendant of the given editable instance in the AST.
bool
Check if this node is contained another node of the given class
bool
Moves the given symbol to a new file and updates its imports and references.
The destination file to move the symbol to.
bool
If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True.
str
The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'.
None
Find the first ancestor of the node of the given type. Does not return itself
Find the first ancestor of the node of the given type. Does not return itself
Prepends the provided code to the beginning of the function body.
str
The code to be prepended to the function body.
None
Reduces an editable to the following condition
None
Deletes this Node and its related extended nodes (e.g. decorators, comments).
bool
Whether to delete surrounding whitespace and formatting. Defaults to True.
int
Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0.
bool
Whether to deduplicate removal transactions at the same location. Defaults to True.
None
Renames a symbol and updates all its references in the codebase.
str
The new name for the symbol.
int
Priority of the edit operation. Defaults to 0.
tuple[NodeId, NodeId]
A tuple containing the file node ID and the new node ID of the renamed symbol.
Renames a local variable and all its usages within a function body.
str
The current name of the local variable to be renamed.
str
The new name to give to the local variable.
bool, optional
If True, matches variable names that contain old_var_name. Defaults to False.
None
The method modifies the AST in place.
Search and replace occurrences of text within this node’s source and its extended nodes.
str
The text or pattern to search for.
str
The text to replace matches with.
int, optional
Maximum number of replacements to make. Defaults to -1 (replace all).
bool, optional
Whether to treat 'old' as a regex pattern. Defaults to False.
int, optional
Priority of the replacement operation. Defaults to 0.
int
The total number of replacements made.
Returns a list of all regex match of regex_pattern
, similar to python’s re.search().
str
The regular expression pattern to search for.
bool
When False, excludes the contents of string literals from the search. Defaults to True.
bool
When False, excludes the contents of comments from the search. Defaults to True.
A list of Editable objects corresponding to the matches found.
Sets a comment to the symbol.
str
The comment text to set.
None
Sets or updates the docstring for the current entity.
str
The new docstring content to set.
None
This method doesn't return anything.
Sets an inline comment to the symbol.
str
The text of the inline comment to be added or updated.
None
Sets the name of a code element.
str
The new name to set for the object.
None
Sets the return type annotation for the function.
str
The new return type annotation to be set. Use an empty string to remove
None
Returns a list of symbols that use or import the exportable object.
The types of usages to search for. Defaults to any.
Returns a list of usages of the exportable object.
Specifies which types of usages to include in the results. Default is any usages.
A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse.