Skip to content

Commit 5442568

Browse files
bombs-kimwillingc
authored andcommitted
Docs: Miscellaneous corrections to simple statements in the language reference (pythonGH-126720)
* Replace: The :keyword:`global` -> The :keyword:`global` statement Add :keyword: when it's needed * Replace repeated links with duoble backticks (cherry picked from commit 94a7a4e)
1 parent 7be8743 commit 5442568

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

Doc/reference/simple_stmts.rst

+11-22
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ The extended form, ``assert expression1, expression2``, is equivalent to ::
406406

407407
These equivalences assume that :const:`__debug__` and :exc:`AssertionError` refer to
408408
the built-in variables with those names. In the current implementation, the
409-
built-in variable :const:`__debug__` is ``True`` under normal circumstances,
409+
built-in variable ``__debug__`` is ``True`` under normal circumstances,
410410
``False`` when optimization is requested (command line option :option:`-O`). The current
411-
code generator emits no code for an assert statement when optimization is
411+
code generator emits no code for an :keyword:`assert` statement when optimization is
412412
requested at compile time. Note that it is unnecessary to include the source
413413
code for the expression that failed in the error message; it will be displayed
414414
as part of the stack trace.
@@ -531,8 +531,8 @@ The :keyword:`!yield` statement
531531
yield_stmt: `yield_expression`
532532

533533
A :keyword:`yield` statement is semantically equivalent to a :ref:`yield
534-
expression <yieldexpr>`. The yield statement can be used to omit the parentheses
535-
that would otherwise be required in the equivalent yield expression
534+
expression <yieldexpr>`. The ``yield`` statement can be used to omit the
535+
parentheses that would otherwise be required in the equivalent yield expression
536536
statement. For example, the yield statements ::
537537

538538
yield <expr>
@@ -544,7 +544,7 @@ are equivalent to the yield expression statements ::
544544
(yield from <expr>)
545545

546546
Yield expressions and statements are only used when defining a :term:`generator`
547-
function, and are only used in the body of the generator function. Using yield
547+
function, and are only used in the body of the generator function. Using :keyword:`yield`
548548
in a function definition is sufficient to cause that definition to create a
549549
generator function instead of a normal function.
550550

@@ -964,25 +964,14 @@ The :keyword:`!global` statement
964964
.. productionlist:: python-grammar
965965
global_stmt: "global" `identifier` ("," `identifier`)*
966966

967-
The :keyword:`global` statement is a declaration which holds for the entire
968-
current code block. It means that the listed identifiers are to be interpreted
969-
as globals. It would be impossible to assign to a global variable without
967+
The :keyword:`global` statement causes the listed identifiers to be interpreted
968+
as globals. It would be impossible to assign to a global variable without
970969
:keyword:`!global`, although free variables may refer to globals without being
971970
declared global.
972971

973-
Names listed in a :keyword:`global` statement must not be used in the same code
974-
block textually preceding that :keyword:`!global` statement.
975-
976-
Names listed in a :keyword:`global` statement must not be defined as formal
977-
parameters, or as targets in :keyword:`with` statements or :keyword:`except` clauses, or in a :keyword:`for` target list, :keyword:`class`
978-
definition, function definition, :keyword:`import` statement, or variable
979-
annotation.
980-
981-
.. impl-detail::
982-
983-
The current implementation does not enforce some of these restrictions, but
984-
programs should not abuse this freedom, as future implementations may enforce
985-
them or silently change the meaning of the program.
972+
The :keyword:`global` statement applies to the entire scope of a function or
973+
class body. A :exc:`SyntaxError` is raised if a variable is used or
974+
assigned to prior to its global declaration in the scope.
986975

987976
.. index::
988977
pair: built-in function; exec
@@ -1018,7 +1007,7 @@ identifiers. If a name is bound in more than one nonlocal scope, the
10181007
nearest binding is used. If a name is not bound in any nonlocal scope,
10191008
or if there is no nonlocal scope, a :exc:`SyntaxError` is raised.
10201009

1021-
The nonlocal statement applies to the entire scope of a function or
1010+
The :keyword:`nonlocal` statement applies to the entire scope of a function or
10221011
class body. A :exc:`SyntaxError` is raised if a variable is used or
10231012
assigned to prior to its nonlocal declaration in the scope.
10241013

0 commit comments

Comments
 (0)