[Python-ideas] globals should accept parenteses for extending beyond 1 line

Terry Reedy tjreedy at udel.edu
Mon Jan 23 14:25:45 EST 2017


On 1/23/2017 1:43 PM, João Matos wrote:
> Hello,
>
> I would like to suggest that globals should follow the existing rule
> (followed by the import statement, the if statement and in other places)
> for extending beyond 1 line using parentheses.
> Like this:
> globals (var_1, var_2,
>     var_3)
>
> instead of what must be done now, which is:
> globals var_1, var_2 \
>     var_3

The declaration keyword is 'global'; 'globals' is the built-in function. 
  In any case

global var_1, var_2
global var_3

works fine.  There is no connection between the names and, unlike with 
import, no operational efficiency is gained by mashing the statements 
together.

This issue should be rare.  The global statement is only needed when one 
is rebinding global names within a function*.  If a function rebinds 10 
different global names, the design should probably be re-examined.

* 'global' at class scope seems useless.

a = 0
class C:
     a = 1

has the same effect as
a = 0
a = 1
class C: pass

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list