[Python-ideas] Mitigating 'self.' Method Pollution

Ethan Furman ethan at stoneleaf.us
Sat Jul 11 02:05:03 CEST 2015

On 07/10/2015 03:31 PM, Michael Hewitt wrote:

> This suggestion is fully backward compatible with existing Python code, but would eliminate the need to pollute future Python methods with copious 'self.' prefixes, thereby improving both readability
> and maintainabilty.

I disagree.  Having a method with nothing but plain variables, plus a "scoping" line towards the top, will cause more work in keeping track of which are instance variables and which are local variables.

Besides that, what happens when you create a function outside a class, and then add it to a class?

class Blah:

def a_func(self, a, b):
     self c, d

Will that work?

   - Yes seems silly in the case of non-method functions

   - No seems artificially restrictive


More information about the Python-ideas mailing list