FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-151950: Fix unresolved AST references in ast.rst by jx2lee · Pull Request #158156 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 8 additions & 7 deletions Doc/library/ast.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Node classes
module and re-exported in :mod:`!ast`.

There is one class defined for each left-hand side symbol in the abstract
grammar (for example, :class:`ast.stmt` or :class:`ast.expr`). In addition,
grammar (for example, :class:`!ast.stmt` or :class:`!ast.expr`). In addition,
there is one class defined for each constructor on the right-hand side; these
classes inherit from the classes for the left-hand side trees. For example,
:class:`ast.BinOp` inherits from :class:`ast.expr`. For production rules
:class:`ast.BinOp` inherits from :class:`!ast.expr`. For production rules
with alternatives (aka "sums"), the left-hand side class is abstract: only
instances of specific constructor nodes are ever created.

Expand All @@ -65,7 +65,7 @@ Node classes

Each instance of a concrete class has one attribute for each child node,
of the type as defined in the grammar. For example, :class:`ast.BinOp`
instances have an attribute :attr:`left` of type :class:`ast.expr`.
instances have an attribute :attr:`!left` of type :class:`!ast.expr`.

If these attributes are marked as optional in the grammar (using a
question mark), the value might be ``None``. If the attributes can have
Expand Down Expand Up @@ -104,10 +104,11 @@ Node classes
one can get the source segment of a one-line expression node using
``source_line[node.col_offset : node.end_col_offset]``.

The constructor of a class :class:`ast.T` parses its arguments as follows:
The constructors of AST node classes parse their arguments as follows:

* If there are positional arguments, there must be as many as there are items
in :attr:`T._fields`; they will be assigned as attributes of these names.
in :attr:`!_fields`; they will be assigned to attributes with
the corresponding names.
* If there are keyword arguments, they will set the attributes of the same
names to the given values.

Expand Down Expand Up @@ -2223,8 +2224,8 @@ Async and await

.. note::
When a string is parsed by :func:`ast.parse`, operator nodes (subclasses
of :class:`ast.operator`, :class:`ast.unaryop`, :class:`ast.cmpop`,
:class:`ast.boolop` and :class:`ast.expr_context`) on the returned tree
of :class:`!ast.operator`, :class:`!ast.unaryop`, :class:`!ast.cmpop`,
:class:`!ast.boolop` and :class:`!ast.expr_context`) on the returned tree
will be singletons. Changes to one will be reflected in all other
occurrences of the same value (for example, :class:`ast.Add`).

Expand Down
Loading

Back | FazBrowse Home | New Git URL