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

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jan 19 00:12:34 CET 2013


Harding, James wrote:
> The name ST_MODE in this example is not a bindable name. The name only 
> lives during compilation and is not accessible at run-time.

I don't think that's a good idea. It would be better for it
to be available at run time like a normal module-level name,
but protected from rebinding.

There may be cases where the compiler can't work out the
value, such as when the module is imported dynamically. Such
code would then continue to work, it just wouldn't be
optimised.

Not having the name present at run time could also lead to
unexpected results. If something tries to rebind the name,
it will succeed, but it won't affect compiler-optimised
code using the name. It would be better if attempting to
rebind a const name raised an exception.

-- 
Greg



More information about the Python-ideas mailing list