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 0x7f23b2e9e6d8>
>>> node.ops
[('<=', <Name.b l.1 at 0x7f23b2e9e2b0>), ('<=', <Name.c l.1 at 0x7f23b2e9e390>)]
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:

iterable(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]#