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

Joao S. O. Bueno jsbueno at python.org.br
Fri Jan 18 12:28:56 CET 2013


On 18 January 2013 05:22, 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.
>

Yes - changing a module's (or object that stands for a module :-)  ) dict type
does work [1] - which would allow for  a "module decorator" to change it.
So, the functionality from Java's "final"  and others can  be had in
Python today, with a small set of "module decorator" utilities.

Now, do I think such a thing should go in the standard library?  -0 for that.

[1] - http://stackoverflow.com/questions/13274916/python-imported-module-is-none/13278043#13278043


> David



More information about the Python-ideas mailing list