Inherits from

Attribute, TSAssignmentStatement, AssignmentStatement, Importable, HasName, Statement, HasValue, Editable, Expression

Properties


dependencies

Symbols that this symbol depends on. Opposite of usages

def dependencies(self) -> list[Union["Symbol", "Import"]]:
    ...

extended

Returns a SymbolGroup of all extended nodes. This allows a common edit interface for all of extended nodes.

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

extended_source

Text representation of all its extended nodes

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

file

The file object that this Editable instance belongs to

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

filepath

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

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

full_name

The full name including the object lookup (if applicable).

Examples: For a.b, the full name is a.b

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

function_calls

Returns all contained function calls. Useful for renaming function invocations etc.

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

index

The 0-based index of the statement in the parent code block.

def index(self) -> int:
    ...

is_optional

Returns True if the attribute is optional, False otherwise

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

is_private

Is this attribute a private method?

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

name

The name of the object excluding whichever namespace precedes it, as a string.

Examples: For a.b, the name is b

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

nested_code_blocks

Returns all nested CodeBlocks within the statement.

def nested_code_blocks(self: Statement[TParent, TBlock]) -> list[TBlock]:
    ...

nested_statements

Returns a list of collections of nested statements within nested blocks in the given statement.

Example:

Given an if block statement:
if (condition) {
statement1;
statement2;
} elif (condition2) {
statement3;
}
Returns a list of collections for each nested block:
[ MultiLineCollection[statement1, statement2], MultiLineCollection[statement3] ]
def nested_statements(self: Statement[TParent, TBlock]) -> list[MultiLineCollection[Statement[TParent, TBlock], Statement[TParent, TBlock]]]:
    ...

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.

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

source

Text representation of the Editable instance

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

value

The value of the object

def value(self) -> Expression | None:
    ...

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.

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

Methods


commit

Commit just this node

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

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.

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

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

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

find_string_literals

Returns a list of all editable substrings within string literals that match strings_to_match

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

flag

Adds a comment so the developer can see this Editable

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

from_assignment

def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSHasBlock, code_block: TSCodeBlock, pos: int, assignment_node: TSNode) -> TSAssignmentStatement:
    ...

get_local_usages

Returns all instances of its usages in the code block as a list of Editable.

def get_local_usages(self: TSAttribute[TSHasBlock, TSCodeBlock]) -> list[Editable]:
    ...

get_name

Returns the Name of the object, as a Name (editable)

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. (Excludes: property identifiers and argument keywords) fuzzy_match allows for partial matching of variable names and effectively does var_name in usage.name

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

insert_after

Inserts new_src after this node

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

insert_before

Inserts new_src before this node

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

remove

Deletes this Node, and optionally its related extended nodes (e.g. decorators, comments, etc.)

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

rename

Renames the attribute as well as all its usages in the class

def rename(self, new_name: str, priority: int = 0) -> None:
    ...

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.

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(…)

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.

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

set_name

Sets the name of the object

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

set_value

Sets the value of the object

def set_value(self, value: str) -> None:
    ...