Skip to content

Commit

Permalink
pythongh-101100: Fix Sphinx warnings in library/ast.rst (python#113289
Browse files Browse the repository at this point in the history
)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
2 people authored and Glyphack committed Jan 27, 2024
1 parent 78f1dc5 commit 7b48fca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Node classes

This is the base of all AST node classes. The actual node classes are
derived from the :file:`Parser/Python.asdl` file, which is reproduced
:ref:`above <abstract-grammar>`. They are defined in the :mod:`_ast` C
:ref:`above <abstract-grammar>`. They are defined in the :mod:`!_ast` C
module and re-exported in :mod:`ast`.

There is one class defined for each left-hand side symbol in the abstract
Expand Down Expand Up @@ -128,14 +128,14 @@ Node classes

.. deprecated:: 3.8

Old classes :class:`ast.Num`, :class:`ast.Str`, :class:`ast.Bytes`,
:class:`ast.NameConstant` and :class:`ast.Ellipsis` are still available,
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. In the meantime,
instantiating them will return an instance of a different class.

.. deprecated:: 3.9

Old classes :class:`ast.Index` and :class:`ast.ExtSlice` are still
Old classes :class:`!ast.Index` and :class:`!ast.ExtSlice` are still
available, but they will be removed in future Python releases.
In the meantime, instantiating them will return an instance of
a different class.
Expand Down Expand Up @@ -1935,8 +1935,7 @@ Function and class definitions
.. class:: arg(arg, annotation, type_comment)

A single argument in a list. ``arg`` is a raw string of the argument
name, ``annotation`` is its annotation, such as a :class:`Str` or
:class:`Name` node.
name; ``annotation`` is its annotation, such as a :class:`Name` node.

.. attribute:: type_comment

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

.. versionchanged:: 3.13
The minimum supported version for feature_version is now (3,7)
The minimum supported version for ``feature_version`` is now ``(3, 7)``.
The ``optimize`` argument was added.


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

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

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

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

.. function:: copy_location(new_node, old_node)

Copy source location (:attr:`lineno`, :attr:`col_offset`, :attr:`end_lineno`,
and :attr:`end_col_offset`) from *old_node* to *new_node* if possible,
Copy source location (:attr:`~ast.AST.lineno`, :attr:`~ast.AST.col_offset`, :attr:`~ast.AST.end_lineno`,
and :attr:`~ast.AST.end_col_offset`) from *old_node* to *new_node* if possible,
and return *new_node*.


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

.. method:: visit_Constant(node)

Handles all constant nodes.

Don't use the :class:`NodeVisitor` if you want to apply changes to nodes
during traversal. For this a special visitor exists
(:class:`NodeTransformer`) that allows modifications.

.. deprecated:: 3.8

Methods :meth:`visit_Num`, :meth:`visit_Str`, :meth:`visit_Bytes`,
:meth:`visit_NameConstant` and :meth:`visit_Ellipsis` are deprecated
Methods :meth:`!visit_Num`, :meth:`!visit_Str`, :meth:`!visit_Bytes`,
:meth:`!visit_NameConstant` and :meth:`!visit_Ellipsis` are deprecated
now and will not be called in future Python versions. Add the
:meth:`visit_Constant` method to handle all constant nodes.

Expand Down Expand Up @@ -2396,7 +2399,7 @@ and classes for traversing abstract syntax trees:
)

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

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

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

tree = ast.parse('foo', mode='eval')
Expand Down
2 changes: 1 addition & 1 deletion Misc/NEWS.d/3.9.0a1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ Restores instantiation of Windows IOCP event loops from the non-main thread.
.. section: Library
Add default implementation of the :meth:`ast.NodeVisitor.visit_Constant`
method which emits a deprecation warning and calls corresponding methody
method which emits a deprecation warning and calls corresponding methods
``visit_Num()``, ``visit_Str()``, etc.

..
Expand Down

0 comments on commit 7b48fca

Please sign in to comment.