@@ -45,7 +45,7 @@ Node classes
45
45
46
46
This is the base of all AST node classes. The actual node classes are
47
47
derived from the :file: `Parser/Python.asdl ` file, which is reproduced
48
- :ref: `above <abstract-grammar >`. They are defined in the :mod: `_ast ` C
48
+ :ref: `above <abstract-grammar >`. They are defined in the :mod: `! _ast ` C
49
49
module and re-exported in :mod: `ast `.
50
50
51
51
There is one class defined for each left-hand side symbol in the abstract
@@ -128,14 +128,14 @@ Node classes
128
128
129
129
.. deprecated :: 3.8
130
130
131
- Old classes :class: `ast.Num `, :class: `ast.Str `, :class: `ast.Bytes `,
132
- :class: `ast.NameConstant ` and :class: `ast.Ellipsis ` are still available,
131
+ Old classes :class: `! ast.Num `, :class: `! ast.Str `, :class: `! ast.Bytes `,
132
+ :class: `! ast.NameConstant ` and :class: `! ast.Ellipsis ` are still available,
133
133
but they will be removed in future Python releases. In the meantime,
134
134
instantiating them will return an instance of a different class.
135
135
136
136
.. deprecated :: 3.9
137
137
138
- Old classes :class: `ast.Index ` and :class: `ast.ExtSlice ` are still
138
+ Old classes :class: `! ast.Index ` and :class: `! ast.ExtSlice ` are still
139
139
available, but they will be removed in future Python releases.
140
140
In the meantime, instantiating them will return an instance of
141
141
a different class.
@@ -1805,8 +1805,7 @@ Function and class definitions
1805
1805
.. class :: arg(arg, annotation, type_comment)
1806
1806
1807
1807
A single argument in a list. ``arg `` is a raw string of the argument
1808
- name, ``annotation `` is its annotation, such as a :class: `Str ` or
1809
- :class: `Name ` node.
1808
+ name; ``annotation `` is its annotation, such as a :class: `Name ` node.
1810
1809
1811
1810
.. attribute :: type_comment
1812
1811
@@ -2140,8 +2139,8 @@ and classes for traversing abstract syntax trees:
2140
2139
.. function :: get_source_segment(source, node, *, padded=False)
2141
2140
2142
2141
Get source code segment of the *source * that generated *node *.
2143
- If some location information (:attr: `lineno `, :attr: `end_lineno `,
2144
- :attr: `col_offset `, or :attr: `end_col_offset `) is missing, return ``None ``.
2142
+ If some location information (:attr: `~ast.AST. lineno `, :attr: `~ast.AST. end_lineno `,
2143
+ :attr: `~ast.AST. col_offset `, or :attr: `~ast.AST. end_col_offset `) is missing, return ``None ``.
2145
2144
2146
2145
If *padded * is ``True ``, the first line of a multi-line statement will
2147
2146
be padded with spaces to match its original position.
@@ -2152,7 +2151,7 @@ and classes for traversing abstract syntax trees:
2152
2151
.. function :: fix_missing_locations(node)
2153
2152
2154
2153
When you compile a node tree with :func: `compile `, the compiler expects
2155
- :attr: `lineno ` and :attr: `col_offset ` attributes for every node that supports
2154
+ :attr: `~ast.AST. lineno ` and :attr: `~ast.AST. col_offset ` attributes for every node that supports
2156
2155
them. This is rather tedious to fill in for generated nodes, so this helper
2157
2156
adds these attributes recursively where not already set, by setting them to
2158
2157
the values of the parent node. It works recursively starting at *node *.
@@ -2167,8 +2166,8 @@ and classes for traversing abstract syntax trees:
2167
2166
2168
2167
.. function :: copy_location(new_node, old_node)
2169
2168
2170
- Copy source location (:attr: `lineno `, :attr: `col_offset `, :attr: `end_lineno `,
2171
- and :attr: `end_col_offset `) from *old_node * to *new_node * if possible,
2169
+ Copy source location (:attr: `~ast.AST. lineno `, :attr: `~ast.AST. col_offset `, :attr: `~ast.AST. end_lineno `,
2170
+ and :attr: `~ast.AST. end_col_offset `) from *old_node * to *new_node * if possible,
2172
2171
and return *new_node *.
2173
2172
2174
2173
@@ -2214,14 +2213,18 @@ and classes for traversing abstract syntax trees:
2214
2213
visited unless the visitor calls :meth: `generic_visit ` or visits them
2215
2214
itself.
2216
2215
2216
+ .. method :: visit_Constant(node)
2217
+
2218
+ Handles all constant nodes.
2219
+
2217
2220
Don't use the :class: `NodeVisitor ` if you want to apply changes to nodes
2218
2221
during traversal. For this a special visitor exists
2219
2222
(:class: `NodeTransformer `) that allows modifications.
2220
2223
2221
2224
.. deprecated :: 3.8
2222
2225
2223
- Methods :meth: `visit_Num `, :meth: `visit_Str `, :meth: `visit_Bytes `,
2224
- :meth: `visit_NameConstant ` and :meth: `visit_Ellipsis ` are deprecated
2226
+ Methods :meth: `! visit_Num `, :meth: `! visit_Str `, :meth: `! visit_Bytes `,
2227
+ :meth: `! visit_NameConstant ` and :meth: `! visit_Ellipsis ` are deprecated
2225
2228
now and will not be called in future Python versions. Add the
2226
2229
:meth: `visit_Constant ` method to handle all constant nodes.
2227
2230
@@ -2250,7 +2253,7 @@ and classes for traversing abstract syntax trees:
2250
2253
)
2251
2254
2252
2255
Keep in mind that if the node you're operating on has child nodes you must
2253
- either transform the child nodes yourself or call the :meth: `generic_visit `
2256
+ either transform the child nodes yourself or call the :meth: `~ast.NodeVisitor. generic_visit `
2254
2257
method for the node first.
2255
2258
2256
2259
For nodes that were part of a collection of statements (that applies to all
@@ -2259,7 +2262,7 @@ and classes for traversing abstract syntax trees:
2259
2262
2260
2263
If :class: `NodeTransformer ` introduces new nodes (that weren't part of
2261
2264
original tree) without giving them location information (such as
2262
- :attr: `lineno `), :func: `fix_missing_locations ` should be called with
2265
+ :attr: `~ast.AST. lineno `), :func: `fix_missing_locations ` should be called with
2263
2266
the new sub-tree to recalculate the location information::
2264
2267
2265
2268
tree = ast.parse('foo', mode='eval')
0 commit comments