While

class astroid.nodes.While(lineno: int | None, col_offset: int | None, parent: NodeNG | None, *, end_lineno: int | None, end_col_offset: int | None)[source]

Bases: MultiLineWithElseBlockNode, Statement

Class representing an ast.While node.

>>> import astroid
>>> node = astroid.extract_node('''
while condition():
    print("True")
''')
>>> node
<While l.2 at 0x7f23b2e4e390>
block_range(lineno: int) tuple[int, int][source]

Get a range from the given line number to where this node ends.

Parameters:

lineno – The line number to start the range at.

Returns:

The range of line numbers that this node belongs to, starting at the given line number.

property blockstart_tolineno

The line on which the beginning of this block ends.

Type:

int

body: list[NodeNG]

The contents of the loop.

get_children()[source]

Get the child nodes below this node.

orelse: list[NodeNG]

The contents of the else block.

postinit(test: NodeNG, body: list[NodeNG], orelse: list[NodeNG]) None[source]
test: NodeNG

The condition that the loop tests.