Skip to content

Commit

Permalink
Removes erroneous explanation of the global about its restrictions;…
Browse files Browse the repository at this point in the history
… a name declared as global can appear later as a target in :keyword:with statements, :keyword:except clauses, :keyword:for target lists, :keyword:class definitions, function definitions, :keyword:import statements.
  • Loading branch information
bombs-kim committed Nov 7, 2024
1 parent 2a6b6b3 commit 83a13b8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions Doc/reference/simple_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -966,19 +966,14 @@ The :keyword:`!global` statement
.. productionlist:: python-grammar
global_stmt: "global" `identifier` ("," `identifier`)*

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

Names listed in a :keyword:`global` statement must not be used in the same code
block textually preceding that :keyword:`!global` statement.

Names listed in a :keyword:`global` statement must not be defined as formal
parameters, or as targets in :keyword:`with` statements or :keyword:`except` clauses, or in a :keyword:`for` target list, :keyword:`class`
definition, function definition, :keyword:`import` statement, or
:term:`variable annotations <variable annotation>`.
The global statement applies to the entire scope of a function or
class body. A :exc:`SyntaxError` is raised if a variable is used or
assigned to prior to its global declaration in the scope.

.. impl-detail::

Expand Down

0 comments on commit 83a13b8

Please sign in to comment.