[Python-Dev] Are PyCFunctions supposed to invisibly consume self when used as a method? (original) (raw)

Brett Cannon brett at python.org
Sat Jun 12 03:57:05 CEST 2010


On Fri, Jun 11, 2010 at 18:30, Guido van Rossum <guido at python.org> wrote:

On Fri, Jun 11, 2010 at 5:41 PM, Benjamin Peterson <benjamin at python.org> wrote:

2010/6/11 Brett Cannon <brett at python.org>:

This "magical" ignoring of self seems to extend to any PyCFunction. Is this dichotomy intentional or just a "fluke"? Maybe this is a hold-over from before we had descriptors and staticmethod, but now that we have these things perhaps this difference should go away.

There are several open feature requests about this. It is merely because PyCFunction does not implement get. Yeah, but this of course is because before descriptors only Python functions were special-cased as methods, and there was known code that depended on this. I'm sure there's even more code that depends on this today (because there is just more code, period :-). Maybe we could offer a decorator that adds a get to a PyCFunction though.

Well, staticmethod seems to work just as well.

I'm going to make this my first request for what to change in Py4K. =)

-Brett



More information about the Python-Dev mailing list