If#

class astroid.nodes.If(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.If node.

>>> import astroid
>>> node = astroid.extract_node('if condition: print(True)')
>>> node
<If l.1 at 0x7f23b2e9dd30>
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 block.

get_children()[source]#

Get the child nodes below this node.

has_elif_block()[source]#
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 statement tests.