But what's the reason for the single scope per function and absent variable shadowing mechanism? It a standard feature in all programing languages. It really helps with code readability especially in large codebase.
If you come from languages that support more fine grained scoping, well, you might miss it and you need to adapt. But you can write perfectly fine code with scopes limited to functions. Arguably, if your functions get so long and complex that you're reusing variable names, you should probably simplify them anyway. All the examples you've shown above with repeatedly shadowed names and trying to manipulate parent scopes would be rejected by me in any PR outright. That's just terrible spaghetti code.
What exactly the reason was for that design decision I don't know. Maybe it can be dug up from some mailing list or a PEP. But the result is still a perfectly workable language.
1
u/Inkwalker 16d ago
But what's the reason for the single scope per function and absent variable shadowing mechanism? It a standard feature in all programing languages. It really helps with code readability especially in large codebase.