On Fri, Jan 18, 2013 at 7:01 PM, Paul Moore <p.f.moore@gmail.com> wrote:
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.
FWIW, people can play whatever games they like by injecting arbitrary objects into sys.modules.
class Locked: ... def __setattr__(self, attr, value): ... raise AttributeError("Rebinding not permitted") ... def __delattr__(self, attr): ... raise AttributeError("Deletion not permitted") ... attr1 = "Hello" ... attr2 = "World" ... sys.modules["example"] = Locked import example example.attr1 'Hello' example.attr2 'World' example.attr2 = "Change" example.attr2 = "World" sys.modules["example"] = Locked() import example example.attr1 'Hello' example.attr2 'World' example.attr2 = "Change" Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in __setattr__ AttributeError: Rebinding not permitted
The import system is even defined to expressly permit doing this in a *module's own code* by replacing "sys.module[__name__]" with a different object. So, any such proposal needs to be made with the awareness that anyone that *really* wants to do this kind of thing already can, but they don't. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia