should "self" be changed?

Terry Reedy tjreedy at udel.edu
Wed May 27 17:59:08 EDT 2015


On 5/27/2015 2:32 AM, Chris Angelico wrote:
> On Wed, May 27, 2015 at 3:23 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> On Wednesday 27 May 2015 06:45, Mark Lawrence wrote:
>>
>>> Apart from breaking all the tools that rely on "self" being spelt "self"
>>> this looks like an excellent idea.
>>
>> Tools which rely on self being spelled "self" are already broken. It's a
>> convention, nothing more, and there are various good reasons for breaking
>> the convention:
>>
>> - metaclasses
>> - classmethods
>> - custom descriptors
>> - nested classes
>
> If it truly relies on it, yes. But if I see a function that has "self"
> as its first parameter, I'm going to read it as a (probable) method
> rather than a stand-alone function, and it wouldn't surprise me if
> introspection and/or source code parsing made the same assumption.

The Idlelib calltips function does not look at names.  It leaves the 
signature of functions as is and removes the first name, whatever it is, 
of bound methods, including bound class methods.  See 
idlelib.CallTips.get_argspec for details. To make sure there is no name 
assumption, test_calltips.py tests that the first name, not 'self', is 
the name removed.  One test method, Tc.t6, has function signature "(no, 
self)", which makes the bound method signature "(self)".


-- 
Terry Jan Reedy




More information about the Python-list mailing list