diff options
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/ast.rst | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index 9ff422c..97ce2f5 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -78,8 +78,8 @@ Node classes node = ast.UnaryOp() node.op = ast.USub() - node.operand = ast.Num() - node.operand.n = 5 + node.operand = ast.Constant() + node.operand.value = 5 node.operand.lineno = 0 node.operand.col_offset = 0 node.lineno = 0 @@ -87,9 +87,16 @@ Node classes or the more compact :: - node = ast.UnaryOp(ast.USub(), ast.Num(5, lineno=0, col_offset=0), + node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0), lineno=0, col_offset=0) +.. deprecated:: 3.8 + + Class :class:`ast.Constant` is now used for all constants. Old classes + :class:`ast.Num`, :class:`ast.Str`, :class:`ast.Bytes`, + :class:`ast.NameConstant` and :class:`ast.Ellipsis` are still available, + but they will be removed in future Python releases. + .. _abstract-grammar: @@ -239,7 +246,7 @@ and classes for traversing abstract syntax trees: def visit_Name(self, node): return copy_location(Subscript( value=Name(id='data', ctx=Load()), - slice=Index(value=Str(s=node.id)), + slice=Index(value=Constant(value=node.id)), ctx=node.ctx ), node) |