Python without explicit self

Oct 28, 2008 18:02 · 166 words · 1 minute read

A month ago, Bruce Eckel wrote about wanting to remove the explicit self parameter from function argument lists in Python. Personally, I don’t mind the explicit self. To me, it makes it feel like all function objects are equal, even those that happen to be methods on classes. That said, Guido wrote an in-depth response, and I certainly recommend that you check that out if you’ve ever considered getting rid of the explicit self.

After reading Guido’s response, I assumed that there must still be some way to eliminate the need for self in Python. Python is an amazingly flexible language. Further, I assumed that somebody had already done it. And sure enough, Michael Foord wrote an article that includes a metaclass called Selfless. As I suspected, this metaclass had to resort to bytecode manipulation. You really can’t change a lot about code objects in Python. I have no intention of using Selfless myself, but the Byteplay library that Michael links to seems neat and interesting.