Compare

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

Bases: NodeNG

Class representing an ast.Compare node.

A Compare node indicates a comparison.

>>> import astroid
>>> node = astroid.extract_node('a <= b <= c')
>>> node
<Compare l.1 at 0x...>
>>> node.ops
[('<=', <Name.b l.1 at 0x...>), ('<=', <Name.c l.1 at 0x...>)]
get_children()[source]

Get the child nodes below this node.

Overridden to handle the tuple fields and skip returning the operator strings.

Returns:

The children.

Return type:

Iterator[NodeNG]

last_child()[source]

An optimized version of list(get_children())[-1]

Returns:

The last child.

Return type:

NodeNG

left: NodeNG

The value at the left being applied to a comparison operator.

ops: list[tuple[str, NodeNG]]

The remainder of the operators and their relevant right hand value.

postinit(left: NodeNG, ops: list[tuple[str, NodeNG]]) None[source]