View Source on Github
Inherits from
PyHasBlock, WhileStatement, HasBlock, Statement, Expression, EditableAttributes
code_block
The code block that represents the body of the while statement.
condition
The condition expression of the while statement.
decorators
Returns a list of decorators associated with this symbol.
docstring
PyCommentGroup | None
Gets the function's docstring.else_statement
the statement that will run if the while loop completes, if any.
extended
Returns a SymbolGroup of all extended nodes associated with this element.
extended_source
strfile
The file object that this Editable instance belongs to.
filepath
strfunction_calls
Returns all function calls within the while statement and its else block.
index
intis_decorated
boolnested_code_blocks
Returns a list of all code blocks nested within the while statement.
nested_statements
Returns a list of statement collections within nested code blocks.
parent
The parent node of this Editable instance.
parent_class
PyClass | None
Find the class this node is contained inparent_function
PyFunction | None
Find the function this node is contained inparent_statement
Statement | None
Find the statement this node is contained inresolved_value
Returns the resolved type of an Expression.
source
strvariable_usages
Returns Editables for all TreeSitter node instances of variable usages within this node's
Methods
add_decorator
Adds a decorator to a function or method.View Source on Github
Parameters
new_decorator
strrequired
skip_if_exists
bool, optionaldefault:False
Returns
boolancestors
Find all ancestors of the node of the given type. Does not return itselfView Source on Github
Returns
edit
Replace the source of thisEditable with new_src.
View Source on Github
Parameters
new_src
strrequired
fix_indentation
booldefault:False
priority
intdefault:0
dedupe
booldefault:True
Returns
Nonefind
Find and return matching nodes or substrings within an Editable instance.View Source on Github
Parameters
strings_to_match
Union[list[str], str]required
exact
booldefault:False
Returns
A list of Editable instances that match the search criteria.
find_string_literals
Returns a list of string literals within this node’s source that match any of the givenView Source on Github
Parameters
strings_to_match
list[str]required
fuzzy_match
booldefault:False
Returns
A list of Editable objects representing the matching string literals.
flag
Adds a visual flag comment to the end of this Editable’s source text.View Source on Github
Returns
get_variable_usages
Returns Editables for all TreeSitter nodes corresponding to instances of variable usageView Source on Github
Parameters
var_name
strrequired
fuzzy_match
booldefault:False
Returns
List of Editable objects representing variable usage nodes matching the given name.
insert_after
Inserts code after this node.View Source on Github
Parameters
new_src
strrequired
fix_indentation
bool, optionaldefault:False
newline
bool, optionaldefault:True
priority
int, optionaldefault:0
dedupe
bool, optionaldefault:True
Returns
Noneinsert_before
Inserts text before this node’s source with optional indentation and newline handling.View Source on Github
Parameters
new_src
strrequired
fix_indentation
booldefault:False
newline
booldefault:True
priority
intdefault:0
dedupe
booldefault:True
Returns
Noneis_child_of
Checks if this node is a descendant of the given editable instance in the AST.View Source on Github
Returns
boolis_wrapped_in
Check if this node is contained another node of the given classView Source on Github
Returns
boolparent_of_type
Find the first ancestor of the node of the given type. Does not return itselfView Source on Github
Returns
Editable | None
parent_of_types
Find the first ancestor of the node of the given type. Does not return itselfView Source on Github
Returns
Editable | None
reduce_condition
Reduces an editable to the following conditionView Source on Github
Returns
Noneremove
Deletes this Node and its related extended nodes (e.g. decorators, comments).View Source on Github
Parameters
delete_formatting
booldefault:True
priority
intdefault:0
dedupe
booldefault:True
Returns
Nonereplace
Search and replace occurrences of text within this node’s source and its extended nodes.View Source on Github
Parameters
old
strrequired
new
strrequired
count
int, optionaldefault:-1
is_regex
bool, optionaldefault:False
priority
int, optionaldefault:0
Returns
intsearch
Returns a list of all regex match ofregex_pattern, similar to python’s re.search().
View Source on Github
Parameters
regex_pattern
strrequired
include_strings
booldefault:True
include_comments
booldefault:True
Returns
A list of Editable objects corresponding to the matches found.
set_docstring
Sets or updates a docstring for a Python function or class.View Source on Github
Parameters
docstring
strrequired
auto_format
bool, optionaldefault:True
clean_format
bool, optionaldefault:True
force_multiline
bool, optionaldefault:False
Returns
None