@@ -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.
@@ -1935,8 +1935,7 @@ Function and class definitions
1935
1935
.. class :: arg(arg, annotation, type_comment)
1936
1936
1937
1937
A single argument in a list. ``arg `` is a raw string of the argument
1938
- name, ``annotation `` is its annotation, such as a :class: `Str ` or
1939
- :class: `Name ` node.
1938
+ name; ``annotation `` is its annotation, such as a :class: `Name ` node.
1940
1939
1941
1940
.. attribute :: type_comment
1942
1941
@@ -2280,8 +2279,8 @@ and classes for traversing abstract syntax trees:
2280
2279
.. function :: get_source_segment(source, node, *, padded=False)
2281
2280
2282
2281
Get source code segment of the *source * that generated *node *.
2283
- If some location information (:attr: `lineno `, :attr: `end_lineno `,
2284
- :attr: `col_offset `, or :attr: `end_col_offset `) is missing, return ``None ``.
2282
+ If some location information (:attr: `~ast.AST. lineno `, :attr: `~ast.AST. end_lineno `,
2283
+ :attr: `~ast.AST. col_offset `, or :attr: `~ast.AST. end_col_offset `) is missing, return ``None ``.
2285
2284
2286
2285
If *padded * is ``True ``, the first line of a multi-line statement will
2287
2286
be padded with spaces to match its original position.
@@ -2292,7 +2291,7 @@ and classes for traversing abstract syntax trees:
2292
2291
.. function :: fix_missing_locations(node)
2293
2292
2294
2293
When you compile a node tree with :func: `compile `, the compiler expects
2295
- :attr: `lineno ` and :attr: `col_offset ` attributes for every node that supports
2294
+ :attr: `~ast.AST. lineno ` and :attr: `~ast.AST. col_offset ` attributes for every node that supports
2296
2295
them. This is rather tedious to fill in for generated nodes, so this helper
2297
2296
adds these attributes recursively where not already set, by setting them to
2298
2297
the values of the parent node. It works recursively starting at *node *.
@@ -2307,8 +2306,8 @@ and classes for traversing abstract syntax trees:
2307
2306
2308
2307
.. function :: copy_location(new_node, old_node)
2309
2308
2310
- Copy source location (:attr: `lineno `, :attr: `col_offset `, :attr: `end_lineno `,
2311
- and :attr: `end_col_offset `) from *old_node * to *new_node * if possible,
2309
+ Copy source location (:attr: `~ast.AST. lineno `, :attr: `~ast.AST. col_offset `, :attr: `~ast.AST. end_lineno `,
2310
+ and :attr: `~ast.AST. end_col_offset `) from *old_node * to *new_node * if possible,
2312
2311
and return *new_node *.
2313
2312
2314
2313
@@ -2354,14 +2353,18 @@ and classes for traversing abstract syntax trees:
2354
2353
visited unless the visitor calls :meth: `generic_visit ` or visits them
2355
2354
itself.
2356
2355
2356
+ .. method :: visit_Constant(node)
2357
+
2358
+ Handles all constant nodes.
2359
+
2357
2360
Don't use the :class: `NodeVisitor ` if you want to apply changes to nodes
2358
2361
during traversal. For this a special visitor exists
2359
2362
(:class: `NodeTransformer `) that allows modifications.
2360
2363
2361
2364
.. deprecated :: 3.8
2362
2365
2363
- Methods :meth: `visit_Num `, :meth: `visit_Str `, :meth: `visit_Bytes `,
2364
- :meth: `visit_NameConstant ` and :meth: `visit_Ellipsis ` are deprecated
2366
+ Methods :meth: `! visit_Num `, :meth: `! visit_Str `, :meth: `! visit_Bytes `,
2367
+ :meth: `! visit_NameConstant ` and :meth: `! visit_Ellipsis ` are deprecated
2365
2368
now and will not be called in future Python versions. Add the
2366
2369
:meth: `visit_Constant ` method to handle all constant nodes.
2367
2370
@@ -2390,7 +2393,7 @@ and classes for traversing abstract syntax trees:
2390
2393
)
2391
2394
2392
2395
Keep in mind that if the node you're operating on has child nodes you must
2393
- either transform the child nodes yourself or call the :meth: `generic_visit `
2396
+ either transform the child nodes yourself or call the :meth: `~ast.NodeVisitor. generic_visit `
2394
2397
method for the node first.
2395
2398
2396
2399
For nodes that were part of a collection of statements (that applies to all
@@ -2399,7 +2402,7 @@ and classes for traversing abstract syntax trees:
2399
2402
2400
2403
If :class: `NodeTransformer ` introduces new nodes (that weren't part of
2401
2404
original tree) without giving them location information (such as
2402
- :attr: `lineno `), :func: `fix_missing_locations ` should be called with
2405
+ :attr: `~ast.AST. lineno `), :func: `fix_missing_locations ` should be called with
2403
2406
the new sub-tree to recalculate the location information::
2404
2407
2405
2408
tree = ast.parse('foo', mode='eval')
0 commit comments