Decorators: an outsider's perspective
Paul Morrow
pm_mon at yahoo.com
Sat Aug 14 18:16:00 EDT 2004
Porky Pig Jr wrote:
> 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.
Not for this kind of thing we don't. The system could enforce the
convention. Or the 'object' class could. See the thread here entitled
antiDecorator metaclass for a demonstration of how this could be done.
More information about the Python-list
mailing list