What do you mean by “…either word…”?
What does “…run of an unknowable amount of existing code…” mean?
What do you mean by “…either word…”?
What does “…run of an unknowable amount of existing code…” mean?
Asking that question suggests that you are not a Python programmer.
My word “meaning” or your word “result” (when run).
It is not possible for us to know the impact (how many people, how much code) of changing the semantics of Python in the way you suggest. This changes the meaning (or result when run, if you prefer) of that code.
Generally people want to be able to run their existing code on a new release of the language interpreter so that they have access to bug-fixes and new features, without having to revisit existing code. Generally the core developers provide that stability.
That is one interpretation - but not the only one,
I would prefer an answer to my original question about block scope in Python.
That question is “Who here thinks Python should…?” Would it really help you to know who? I mean, you even asked whether Chris is a Python programmer, so you don’t seem to know much about people here.
Let’s focus on programming and the problem I have identified with no block scope in Python while-loops, for-loops and if-elif-else statements.
Can you understand how having no block scope in Python while-loops, for-loops and if-elif-else statements is a problem?
Sorry no. I can imagine an other Python with your proposed block scope and then I see the same problem as @bwoodsend has mentioned above. But I know, that python has not a relevant block scope problem.
The prospect of explicit statement local variables has been explored before (PEP 3150 – Statement local namespaces (aka “given” clause) | peps.python.org for example), and comprehension expressions keep their iteration variables local to the comprehension.
So it might theoretically be possible to use the same mechanism as comprehensions use to add “suite local” variables. For backwards compatibility reasons, this would require new syntax, such as the suite level local
declarations suggested earlier in the thread, or (more intrusively) giving annotated declarations different behaviour from those without type hints (if you look broadly across languages, you’ll find that block scoped variables tend to go hand in hand with dedicated and mandatory local variable declaration syntax).
The question then becomes: why? What increase in language power and expressiveness would be provided by this that cannot already be obtained by using different variable names for the different purposes?
Just to try to explicate what I think other people are saying here: a lot of people look at that and say “The problem isn’t that Python doesn’t have block scopes, the problem is that the programmer chose the variable name poorly and it overwrote an existing variable.” Having to be aware of your variable names in various scopes is an issue in basically any language; your example just shows how a lack of such awareness can bite you in Python.
This is exacerbated by the fact that the code in your example is rather abstract and doesn’t accomplish any meaningful task. So it’s hard to see why a
being 3 rather than 5 at the end matters.
For moderation clarity: the final responses here explain eloquently why block scope will never happen. Further discussion is not productive.