[Python-ideas] 'const' and 'require' statements

Nick Coghlan ncoghlan at gmail.com
Fri Jan 18 09:08:01 CET 2013


On Fri, Jan 18, 2013 at 5:22 PM, David Townshend <aquavitae69 at gmail.com> wrote:
> As has already been pointed out, syntax to allow compile-time optimisations
> doesn't really make much sense in python, especially considering the
> optimisations Pypy already carries out.  Some sort of "finalise" option may
> be somewhat useful (although I can't say I've ever needed it).  To avoid
> adding a new keyword it could be implementer as a function, e.g.
> finalise("varname") or finalise(varname="value").  In a class, this would
> actually be quite easy to implement by simply replacing the class dict with
> a custom dict designed to restrict writing to finalised names.  I haven't
> ever tried changing the globals dict type, but I imagine it would be
> possible, or at least possible to to provide a method to change it.  I
> haven't thought through all the implications of doing it this way, but I'd
> rather see something like this than a new "const" keyword.

While you won't see module level support (beyond the ability to place
arbitrary classes in sys.modules), this is already completely possible
through the descriptor protocol (e.g. by creating read-only
properties).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list