Skip to content

Commit 93f5e26

Browse files
miss-islingtonencukoubrianschubert
authored
[3.14] gh-137376: Add note on top-level global declarations (GH-137707) (GH-138023)
(cherry picked from commit 9f05f98) Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Brian Schubert <[email protected]>
1 parent 7d9b267 commit 93f5e26

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

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

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

0 commit comments

Comments
 (0)