Skip to content

Commit 76bef38

Browse files
hugovkAlexWaygood
andauthored
gh-101100: Fix Sphinx warnings in library/ast.rst (#113289)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 6a69b80 commit 76bef38

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Doc/library/ast.rst

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -1935,8 +1935,7 @@ Function and class definitions
19351935
.. class:: arg(arg, annotation, type_comment)
19361936

19371937
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.
19401939

19411940
.. attribute:: type_comment
19421941

@@ -2210,7 +2209,7 @@ and classes for traversing abstract syntax trees:
22102209
Added ``type_comments``, ``mode='func_type'`` and ``feature_version``.
22112210

22122211
.. versionchanged:: 3.13
2213-
The minimum supported version for feature_version is now (3,7)
2212+
The minimum supported version for ``feature_version`` is now ``(3, 7)``.
22142213
The ``optimize`` argument was added.
22152214

22162215

@@ -2286,8 +2285,8 @@ and classes for traversing abstract syntax trees:
22862285
.. function:: get_source_segment(source, node, *, padded=False)
22872286

22882287
Get source code segment of the *source* that generated *node*.
2289-
If some location information (:attr:`lineno`, :attr:`end_lineno`,
2290-
:attr:`col_offset`, or :attr:`end_col_offset`) is missing, return ``None``.
2288+
If some location information (:attr:`~ast.AST.lineno`, :attr:`~ast.AST.end_lineno`,
2289+
:attr:`~ast.AST.col_offset`, or :attr:`~ast.AST.end_col_offset`) is missing, return ``None``.
22912290

22922291
If *padded* is ``True``, the first line of a multi-line statement will
22932292
be padded with spaces to match its original position.
@@ -2298,7 +2297,7 @@ and classes for traversing abstract syntax trees:
22982297
.. function:: fix_missing_locations(node)
22992298

23002299
When you compile a node tree with :func:`compile`, the compiler expects
2301-
:attr:`lineno` and :attr:`col_offset` attributes for every node that supports
2300+
:attr:`~ast.AST.lineno` and :attr:`~ast.AST.col_offset` attributes for every node that supports
23022301
them. This is rather tedious to fill in for generated nodes, so this helper
23032302
adds these attributes recursively where not already set, by setting them to
23042303
the values of the parent node. It works recursively starting at *node*.
@@ -2313,8 +2312,8 @@ and classes for traversing abstract syntax trees:
23132312

23142313
.. function:: copy_location(new_node, old_node)
23152314

2316-
Copy source location (:attr:`lineno`, :attr:`col_offset`, :attr:`end_lineno`,
2317-
and :attr:`end_col_offset`) from *old_node* to *new_node* if possible,
2315+
Copy source location (:attr:`~ast.AST.lineno`, :attr:`~ast.AST.col_offset`, :attr:`~ast.AST.end_lineno`,
2316+
and :attr:`~ast.AST.end_col_offset`) from *old_node* to *new_node* if possible,
23182317
and return *new_node*.
23192318

23202319

@@ -2360,14 +2359,18 @@ and classes for traversing abstract syntax trees:
23602359
visited unless the visitor calls :meth:`generic_visit` or visits them
23612360
itself.
23622361

2362+
.. method:: visit_Constant(node)
2363+
2364+
Handles all constant nodes.
2365+
23632366
Don't use the :class:`NodeVisitor` if you want to apply changes to nodes
23642367
during traversal. For this a special visitor exists
23652368
(:class:`NodeTransformer`) that allows modifications.
23662369

23672370
.. deprecated:: 3.8
23682371

2369-
Methods :meth:`visit_Num`, :meth:`visit_Str`, :meth:`visit_Bytes`,
2370-
:meth:`visit_NameConstant` and :meth:`visit_Ellipsis` are deprecated
2372+
Methods :meth:`!visit_Num`, :meth:`!visit_Str`, :meth:`!visit_Bytes`,
2373+
:meth:`!visit_NameConstant` and :meth:`!visit_Ellipsis` are deprecated
23712374
now and will not be called in future Python versions. Add the
23722375
:meth:`visit_Constant` method to handle all constant nodes.
23732376

@@ -2396,7 +2399,7 @@ and classes for traversing abstract syntax trees:
23962399
)
23972400

23982401
Keep in mind that if the node you're operating on has child nodes you must
2399-
either transform the child nodes yourself or call the :meth:`generic_visit`
2402+
either transform the child nodes yourself or call the :meth:`~ast.NodeVisitor.generic_visit`
24002403
method for the node first.
24012404

24022405
For nodes that were part of a collection of statements (that applies to all
@@ -2405,7 +2408,7 @@ and classes for traversing abstract syntax trees:
24052408

24062409
If :class:`NodeTransformer` introduces new nodes (that weren't part of
24072410
original tree) without giving them location information (such as
2408-
:attr:`lineno`), :func:`fix_missing_locations` should be called with
2411+
:attr:`~ast.AST.lineno`), :func:`fix_missing_locations` should be called with
24092412
the new sub-tree to recalculate the location information::
24102413

24112414
tree = ast.parse('foo', mode='eval')

Misc/NEWS.d/3.9.0a1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ Restores instantiation of Windows IOCP event loops from the non-main thread.
20692069
.. section: Library
20702070
20712071
Add default implementation of the :meth:`ast.NodeVisitor.visit_Constant`
2072-
method which emits a deprecation warning and calls corresponding methody
2072+
method which emits a deprecation warning and calls corresponding methods
20732073
``visit_Num()``, ``visit_Str()``, etc.
20742074

20752075
..

0 commit comments

Comments
 (0)