
On 18 January 2013 04:28, Cameron Simpson <cs@zip.com.au> wrote:
If I'd written his proposal I'd have probably termed these things "bind-once", generating names that may not be rebound. They would still need to be carefully placed if the compiler were to have the option of constant folding i.e. they're need to be outside function and class definitions, determinable from static analysis.
A few thoughts along the same lines: 1. Global lookups are not likely to be the performance bottleneck in any real code, so constant folding is not going to be a particular benefit. 2. The idea of names that can't be rebound isn't particularly Pythonic (given that things like private class variables aren't part of the language) 3. Constants that can't be imported from another module aren't much use, and yet if they can be imported you have real problems enforcing the non-rebindability. Consider: import my_consts print(my_consts.A_VALUE) # Presumably a constant value, but obviously the compiler can't inline it... my_consts.A_VALUE = 12 # The language has no chance to prevent this without completely changing module semantics Named values are obviously a good thing, but I see little benefit, and a lot of practical difficulty, with the idea of "enforced const-ness" in Python. Paul.