Skip to main content

Inherits from

Usable, HasBlock, File, Importable, Expression, Editable, HasName

Attributes

classes

code_block

content

decorators

directory

docstring

extended

extended_source

extension

file

file_path

filepath

full_name

function_calls

functions

global_vars

import_module_name

import_statements

importers

imports

inbound_imports

is_binary

is_decorated

name

owners

parent

parent_class

parent_function

parent_statement

path

resolved_value

source

start_byte

symbols_sorted_topologically

variable_usages

Methods

add_decorator

Adds a decorator to a function or method.

add_import

Adds an import to the file.

add_symbol

Adds symbol to the file.

add_symbol_from_source

Adds a symbol to a file from a string representation.

ancestors

Find all ancestors of the node of the given type. Does not return itself

dependencies

Returns a list of symbols that this symbol depends on.

edit

Replace the source of this file with new_src.

find

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

find_by_byte_range

Finds all editable objects that overlap with the given byte range in the file.

find_string_literals

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

flag

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

get_class

Returns a specific Class by full name. Returns None if not found.

get_function

Returns a specific Function by name.

get_global_var

Returns a specific global var by name. Returns None if not found.

get_import

Returns the import with matching alias. Returns None if not found.

get_name

Returns the name node of the object.

get_symbol

Gets a symbol by its name from the file.

get_variable_usages

Returns Editables for all TreeSitter nodes corresponding to instances of variable usage

has_import

Returns True if the file has an import with the given alias.

insert_after

Inserts code after this node.

insert_before

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

is_child_of

Checks if this node is a descendant of the given editable instance in the AST.

is_wrapped_in

Check if this node is contained another node of the given class

parent_of_type

Find the first ancestor of the node of the given type. Does not return itself

parent_of_types

Find the first ancestor of the node of the given type. Does not return itself

reduce_condition

Reduces an editable to the following condition

remove

Removes the file from the file system and graph.

remove_unused_exports

Removes unused exports from the file.

rename

Renames a symbol and updates all its references in the codebase.

replace

Replace occurrences of text in the file. Returns a list of all regex match of regex_pattern, similar to python’s re.search().

set_docstring

Sets or updates the docstring for the current entity.

set_name

Sets the name of a code element.

symbol_can_be_added

Checks if the file type supports adding the given symbol.

symbol_usages

Returns a list of symbols that use or import the exportable object.

symbols

Returns all Symbols in the file, sorted by position in the file.

update_filepath

Renames the file and updates all imports to point to the new location.

usages

Returns a list of usages of the exportable object.