Skip to content

Commit 72f0c74

Browse files
committed
gh-137376: Add note on top-level global declarations
1 parent 9e512ae commit 72f0c74

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
@@ -971,10 +971,17 @@ as globals. It would be impossible to assign to a global variable without
971971
:keyword:`!global`, although free variables may refer to globals without being
972972
declared global.
973973

974-
The :keyword:`global` statement applies to the entire scope of a function or
975-
class body. A :exc:`SyntaxError` is raised if a variable is used or
974+
The :keyword:`!global` statement applies to the entire current scope
975+
(module, function body or class class definition).
976+
A :exc:`SyntaxError` is raised if a variable is used or
976977
assigned to prior to its global declaration in the scope.
977978

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

0 commit comments

Comments
 (0)