[Python-ideas] Before and after the colon in funciton defs.

Terry Reedy tjreedy at udel.edu
Wed Sep 21 05:36:35 CEST 2011

On 9/20/2011 1:09 PM, Guido van Rossum wrote:
> On Tue, Sep 20, 2011 at 9:59 AM, Terry Reedy<tjreedy at udel.edu>  wrote:

>> The problem with an earlybind statement in the body is that it is in the
>> body, which should be runtime stuff. I would prefer something in the header.
>> A semi-colon or other char would be sufficient syntactically:
>> def f(a; len, alist=[]): alist.append(a); return len(alist)
>> where a bare identifier like 'len' *means* 'len=len'.
> I would be much more interested in a tweak to the language semantics
> where the compiler is allowed to assume that "len means len" if there
> is no global assignment to it in a module. There are many past threads
> about this topic. It should make the feature proposed here unnecessary
> -- at least its use for manual micro-optimizations, which I mostly
> find an offense to the reader (even in the shortened form proposed
> here).

For those not party to the earlier threads, this alternate proposal 
would bread any code that monkeypatches an imported-module-only override 
of a builtin, something like:

def mylen(o): return <whatever>
import mod; mod.len = mylen

I do not mind the semantic change itself, and it would benefit nearly 
all code, including module-level code would not be affected by def 
gimmicks. Some issues I see that perhaps were discussed, but I do not 
remember: 1) module.__setattr__ should then raise an exception at such 
attempts; 2) it makes the language more context sensitive than it 
currently is; 3) compile() should apply the rule even for single 
statements or even expressions.

Terry Jan Reedy

More information about the Python-ideas mailing list