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>
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() bool[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.