Attack a sacred Python Cow

Terry Reedy tjreedy at udel.edu
Fri Jul 25 16:47:47 EDT 2008



Nikolaus Rath wrote:
> Terry Reedy <tjreedy at udel.edu> writes:
>> Torsten Bronger wrote:
>>> Hallöchen!
>>  > And why does this make the implicit insertion of "self" difficult?
>>> I could easily write a preprocessor which does it after all.
>> class C():
>>   def f():
>>     a = 3
>>
>> Inserting self into the arg list is trivial.  Mindlessly deciding
>> correctly whether or not to insert 'self.' before 'a' is impossible
>> when 'a' could ambiguously be either an attribute of self or a local
>> variable of f.  Or do you and/or Jordan plan to abolish local
>> variables for methods?
> 
> Why do you think that 'self' should be inserted anywhere except in the
> arg list? AFAIU, the idea is to remove the need to write 'self' in the
> arg list, not to get rid of it entirely.

Because you must prefix self attributes with 'self.'.  If you do not use 
any attributes of the instance of the class you are making the function 
an instance method of, then it is not really an instance method and need 
not and I would say should not be masqueraded as one.  If the function 
is a static method, then it should be labeled as one and no 'self' is 
not needed and auto insertion would be a mistake.  In brief, I assume 
the OP wants 'self' inserted in the body because inserting it only in 
the parameter list and never using it in the body is either silly or wrong.

tjr




More information about the Python-list mailing list