Decorators: an outsider's perspective

Porky Pig Jr porky_pig_jr at my-deja.com
Sat Aug 14 18:04:57 EDT 2004


Paul Morrow <pm_mon at yahoo.com> wrote in message > class Foo:
>     def blah(a, b):         # this is clearly a static method
>        pass
> 
>     def blah(self, a, b):   # this is clearly an instance method
>        pass
> 
>     def blah(klass, a, b):  # this is clearly a class method
>        pass
> 
> Python was built (successfully) on the assumption that obvious 
> interpretations of the code obviate the need for declarations.  Why 
> wouldn't we continue with that mindset?
> 
> Paul

I don't think it's a good example. 'self' is a convention, not the
reserved word. Nothing can prevent anyone from using some other word.
Strictly speaking, the fact that the first parameter is called 'self'
does not imply anything. Ditto for 'klass' (or rather 'cls' which is
used by the number of references). Again, it's not a reserved word.
What if I've decided to use parameter name 'cls' in static function? 
What if I've decided to use 'this' instead of 'self'? So - either we
need some mechanism to enforce the keywords 'self', 'cls', or -- we
back to square one: we need decorators.



More information about the Python-list mailing list