@@ -45,7 +45,7 @@ Node classes
4545
4646 This is the base of all AST node classes. The actual node classes are
4747 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
4949 module and re-exported in :mod: `ast `.
5050
5151 There is one class defined for each left-hand side symbol in the abstract
@@ -128,14 +128,14 @@ Node classes
128128
129129.. deprecated :: 3.8
130130
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,
133133 but they will be removed in future Python releases. In the meantime,
134134 instantiating them will return an instance of a different class.
135135
136136.. deprecated :: 3.9
137137
138- Old classes :class: `ast.Index ` and :class: `ast.ExtSlice ` are still
138+ Old classes :class: `! ast.Index ` and :class: `! ast.ExtSlice ` are still
139139 available, but they will be removed in future Python releases.
140140 In the meantime, instantiating them will return an instance of
141141 a different class.
@@ -1805,8 +1805,7 @@ Function and class definitions
18051805.. class :: arg(arg, annotation, type_comment)
18061806
18071807 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.
18101809
18111810 .. attribute :: type_comment
18121811
@@ -2140,8 +2139,8 @@ and classes for traversing abstract syntax trees:
21402139.. function :: get_source_segment(source, node, *, padded=False)
21412140
21422141 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 ``.
21452144
21462145 If *padded * is ``True ``, the first line of a multi-line statement will
21472146 be padded with spaces to match its original position.
@@ -2152,7 +2151,7 @@ and classes for traversing abstract syntax trees:
21522151.. function :: fix_missing_locations(node)
21532152
21542153 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
21562155 them. This is rather tedious to fill in for generated nodes, so this helper
21572156 adds these attributes recursively where not already set, by setting them to
21582157 the values of the parent node. It works recursively starting at *node *.
@@ -2167,8 +2166,8 @@ and classes for traversing abstract syntax trees:
21672166
21682167.. function :: copy_location(new_node, old_node)
21692168
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,
21722171 and return *new_node *.
21732172
21742173
@@ -2214,14 +2213,18 @@ and classes for traversing abstract syntax trees:
22142213 visited unless the visitor calls :meth: `generic_visit ` or visits them
22152214 itself.
22162215
2216+ .. method :: visit_Constant(node)
2217+
2218+ Handles all constant nodes.
2219+
22172220 Don't use the :class: `NodeVisitor ` if you want to apply changes to nodes
22182221 during traversal. For this a special visitor exists
22192222 (:class: `NodeTransformer `) that allows modifications.
22202223
22212224 .. deprecated :: 3.8
22222225
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
22252228 now and will not be called in future Python versions. Add the
22262229 :meth: `visit_Constant ` method to handle all constant nodes.
22272230
@@ -2250,7 +2253,7 @@ and classes for traversing abstract syntax trees:
22502253 )
22512254
22522255 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 `
22542257 method for the node first.
22552258
22562259 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:
22592262
22602263 If :class: `NodeTransformer ` introduces new nodes (that weren't part of
22612264 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
22632266 the new sub-tree to recalculate the location information::
22642267
22652268 tree = ast.parse('foo', mode='eval')
0 commit comments