Attack a sacred Python Cow

Nikolaus Rath Nikolaus at
Sat Jul 26 11:08:12 CEST 2008

Terry Reedy <tjreedy at> writes:
> Nikolaus Rath wrote:
>> Terry Reedy <tjreedy at> 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.

I think you misunderstood him. What he wants is to write

class foo:
   def bar(arg):
       self.whatever = arg + 1

instead of

class foo:
   def bar(self, arg)
       self.whatever = arg + 1

so 'self' should *automatically* only be inserted in the function
declaration, and *manually* be typed for attributes.



 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
                                                         -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

More information about the Python-list mailing list