Skip to content

Commit b3affab

Browse files
encukoubrianschubert
authored andcommitted
gh-137376: Add note on top-level global declarations (GH-137707)
(cherry picked from commit 9f05f98) Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Brian Schubert <[email protected]>
1 parent c04b3de commit b3affab

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Doc/reference/simple_stmts.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,17 @@ as globals. It would be impossible to assign to a global variable without
969969
:keyword:`!global`, although free variables may refer to globals without being
970970
declared global.
971971

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
972+
The :keyword:`!global` statement applies to the entire current scope
973+
(module, function body or class definition).
974+
A :exc:`SyntaxError` is raised if a variable is used or
974975
assigned to prior to its global declaration in the scope.
975976

977+
At the module level, all variables are global, so a :keyword:`!global`
978+
statement has no effect.
979+
However, variables must still not be used or
980+
assigned to prior to their :keyword:`!global` declaration.
981+
This requirement is relaxed in the interactive prompt (:term:`REPL`).
982+
976983
.. index::
977984
pair: built-in function; exec
978985
pair: built-in function; eval

0 commit comments

Comments
 (0)