Dict¶
- class astroid.nodes.Dict(lineno: int | None, col_offset: int | None, parent: NodeNG | None, *, end_lineno: int | None, end_col_offset: int | None)[source]¶
Bases:
NodeNG
,DictInstance
Class representing an
ast.Dict
node.A
Dict
is a dictionary that is created with{}
syntax.>>> import astroid >>> node = astroid.extract_node('{1: "1"}') >>> node <Dict.dict l.1 at 0x7f23b2e35cc0>
- bool_value(context: InferenceContext | None = None)[source]¶
Determine the boolean value of this node.
- Returns:
The boolean value of this node.
- Return type:
- get_children()[source]¶
Get the key and value nodes below this node.
Children are returned in the order that they are defined in the source code, key first then the value.
- Returns:
The children.
- Return type:
iterable(NodeNG)
- getitem(index: Const | Slice, context: InferenceContext | None = None) NodeNG [source]¶
Get an item from this node.
- Parameters:
index – The node to use as a subscript index.
- Raises:
AstroidTypeError – When the given index cannot be used as a subscript index, or if this node is not subscriptable.
AstroidIndexError – If the given index does not exist in the dictionary.
- infer_unary_op(op)¶
- items: list[tuple[InferenceResult, InferenceResult]]¶
The key-value pairs contained in the dictionary.
- itered()[source]¶
An iterator over the keys this node contains.
- Returns:
The keys of this node.
- Return type:
iterable(NodeNG)
- last_child()[source]¶
An optimized version of list(get_children())[-1]
- Returns:
The last child, or None if no children exist.
- Return type:
NodeNG or None