<div dir="ltr"><div>Hi,<br>I couldn't find whether this was proposed or not, but seems interesting to me:<br></div><div><br></div>Whenever there's an assignment inside a big function, we think it is a local variable, but it could have been defined as global on top and that can mess things up if not checked.<br>

<div><br></div><div>So, I why not have attribute syntax on "global" and "nonlocal" keywords?<br></div><div>Something that is written like:<br><span style="font-family:courier new,monospace"><br>x = 10<br>

def increment():<br>    global x<br>    x += 1</span><br><br></div><div>could be replaced by<br><br><span style="font-family:courier new,monospace">x = 10<br>def increment():<br></span></div><div><span style="font-family:courier new,monospace">    global.x += 1</span><br>

</div><div><div><br></div><div>another example:<br><br><span style="font-family:courier new,monospace">def foo(x):<br>    def bar():<br>        return nonlocal.x + 1<br>    return bar</span><br></div><div><br></div><div>
</div>
<div>These should generate the same "LOAD_GLOBAL" and "LOAD_DEREF" bytecodes, so "global" and "nonlocal" will not be objects nor passed as arguments.<br></div><div><br></div><div>That way you can have both "global.x", "nonlocal.x" and "x" variables without conflict.<br>

<span style="font-family:courier new,monospace"><br></span></div><div><span style="font-family:courier new,monospace">x = 10<br></span></div><div><span style="font-family:courier new,monospace">def f(x):<br></span></div>
<div>
<span style="font-family:courier new,monospace">   def g():<br></span></div><div><span style="font-family:courier new,monospace">       # how can I set both "x" variables inside here?</span><br></div><div><br></div>

<div>"Namespaces are one honking great idea -- let's do more of those!"<br></div><div><br></div><div>--<br clear="all"><div>Joćo Bernardo</div>
</div></div></div>