Skip to main content

Inherits from

CodeBlock, Expression, Editable

Attributes

assignment_statements

assignments

attributes

comments

extended

extended_source

file

filepath

function_calls

if_blocks

level

local_var_assignments

parent

parent_block

parent_class

parent_function

parent_statement

resolved_value

return_statements

source

statements

symbol_statements

variable_usages

Methods

ancestors

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

edit

Replace the source of this Editable with new_src.

find

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

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_assignments

Returns a list of assignments with the specified variable name.

get_attributes

Returns attributes from the code block, with the option to include or exclude private

get_comment

Gets the first comment statement containing a specific text string.

get_local_var_assignment

Returns the first code statement that assigns a local variable with the specified name.

get_local_var_assignments

Returns all instances of local variable assignments that match the specified variable

get_statements

Returns all statements of a given type up to the specified block level.

get_variable_usages

Returns all instances of variable usages in a code block.

indent

Adjusts the indentation level of the entire code block.

insert_after

Inserts source code at the bottom of the code block.

insert_before

Inserts new source code at the top of the code block.

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

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

rename_variable_usages

Renames all instances of variable usages in the code block.

replace

Search and replace occurrences of text within this node’s source and its extended nodes. Returns a list of all regex match of regex_pattern, similar to python’s re.search().

unwrap

Unwraps a code block by removing its opening and closing braces.

wrap

Wraps a code block with a statement and indents it.