Const¶
- class astroid.nodes.Const(value: ~typing.Any, lineno: int | None = None, col_offset: int | None = None, parent: ~astroid.nodes.node_ng.NodeNG = <__SyntheticRoot.__astroid_synthetic l.0>, kind: str | None = None, *, end_lineno: int | None = None, end_col_offset: int | None = None)[source]¶
Bases:
NoChildrenNode
,Instance
Class representing any constant including num, str, bool, None, bytes.
>>> import astroid >>> node = astroid.extract_node('(5, "This is a string.", True, None, b"bytes")') >>> node <Tuple.tuple l.1 at 0x7f23b2e358d0> >>> list(node.get_children()) [<Const.int l.1 at 0x7f23b2e35940>, <Const.str l.1 at 0x7f23b2e35978>, <Const.bool l.1 at 0x7f23b2e359b0>, <Const.NoneType l.1 at 0x7f23b2e359e8>, <Const.bytes l.1 at 0x7f23b2e35a20>]
- bool_value(context: InferenceContext | None = None)[source]¶
Determine the boolean value of this node.
- Returns:
The boolean value of this node.
- Return type:
- getitem(index, context: InferenceContext | None = None)[source]¶
Get an item from this node if subscriptable.
- Parameters:
index (Const or Slice) – 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.
- has_dynamic_getattr() bool [source]¶
Check if the node has a custom __getattr__ or __getattribute__.
- Returns:
Whether the class has a custom __getattr__ or __getattribute__. For a
Const
this is alwaysFalse
.
- infer_binary_op(**kwargs: _P.kwargs) Generator[InferenceResult] ¶
- infer_unary_op(op)¶
- kind: str | None¶
“The string prefix. “u” for u-prefixed strings and
None
otherwise. Python 3.8+ only.
- pytype() str [source]¶
Get the name of the type that this node represents.
- Returns:
The name of the type.
- value¶
The value that the constant represents.