Python handles globals badly.

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Sep 12 04:51:17 CEST 2015


On 11/09/2015 09:42, Steven D'Aprano wrote:
> On Fri, 11 Sep 2015 10:35 am, Ian Kelly wrote:
>
>> On Thu, Sep 10, 2015 at 4:25 PM,  <tdev at freenet.de> wrote:
> [...]
>>> So the compiler knows the distiction between global and local already.
>>
>> As we've said before, it doesn't. The compiler's current rules are
>> fairly simple:
>>
>> 1) If it's in the function's argument list, it's an argument (and
>> therefore local).
>> 2) If it's explicitly declared global, then it's global.
>> 3) If it's never assigned within the function, then it's global.
>
> Almost. If it's never assigned within the function, then it is looked up
> according to the non-local scoping rules:
>
> - closures and enclosing functions (if any);
> - globals;
> - builtins;
>
> in that order.
>
>
>> 4) Otherwise, it's local.
>
> "Otherwise" meaning "if it is assigned to", except that "del" counts as an
> assignment. That is:
>
> def spam():
>      del x
>
> makes x a local variable inside the function spam.
>
>
> There's also a bunch of specialised and complicated rules for what happens
> if you make a star import ("from module import *") inside a function, or
> call eval or exec without specifying a namespace. Both of these things are
> now illegal in Python 3.
>
> And lastly, in Python 3 only, there is also a nonlocal declaration which
> works like global except it applies only to closures and enclosing
> functions.
>
>
>>> Another proof about identation:
>>> The parser can recognise identation with tabs and spaces.
>>
>> You can use tabs *or* spaces.
>
> In Python 3.
>
> In Python 2, you can mix tabs *and* spaces, and Python will try to guess
> what you mean. This causes more trouble than it is worth, and is removed in
> Python 3.
>
>
> [...]
>> I really doubt that you're going to gain any traction with this one,
>> because the decision that was made with Python 3 was to make the
>> compiler *more* rigid about not mixing tabs and spaces, not less.
>
> Correct.
>
> [...]
>>> Who is responding or has responded?
>>> Extreme Programmers, Python-Hardliner, Python-Evangelists, ... .
>>> Presumably no core Python Programmers (wrting compiler and standard
>>> library stuff)
>>
>> Ad hominem.
>
> For the record, I am the author of the statistics module in Python 3.4, and
> Terry Reedy is the very active maintainer of IDLE. If I have missed anyone,
> my apologies. So, yes, there are core developers here.
>
> (Although not any of the senior core devs, as far as I know.)
>

IIRC Serhiy Storchaka pops in occasionally, as on the one genuine report 
from the RUE about the FSR.  Slight aside, I swear blind that Serhiy 
never sleeps as he always seems to be doing something on the bug tracker.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Python-list mailing list