Slice#

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

>>> import astroid
>>> node = astroid.extract_node('things[1:3]')
>>> node
<Subscript l.1 at 0x7f23b2e71f60>
>>> node.slice
<Slice l.1 at 0x7f23b2e71e80>
display_type() Literal['Slice'][source]#

A human readable type of this node.

Returns:

The type of this node.

get_children()[source]#

Get the child nodes below this node.

getattr(attrname, context: InferenceContext | None = None)[source]#
igetattr(attrname: str, context: InferenceContext | None = None) Iterator[SuccessfulInferenceResult][source]#

Infer the possible values of the given attribute on the slice.

Parameters:

attrname – The name of the attribute to infer.

Returns:

The inferred possible values.

lower: NodeNG | None#

The lower index in the slice.

postinit(lower: NodeNG | None, upper: NodeNG | None, step: NodeNG | None) None[source]#
pytype() Literal['builtins.slice'][source]#

Get the name of the type that this node represents.

Returns:

The name of the type.

step: NodeNG | None#

The step to take between indexes.

upper: NodeNG | None#

The upper index in the slice.