[Python-Dev] Missing operator.call (original) (raw)

Steven Bethard steven.bethard at gmail.com
Wed Feb 4 21:07:18 CET 2009


On Wed, Feb 4, 2009 at 10:50 AM, Brett Cannon <brett at python.org> wrote:

On Wed, Feb 4, 2009 at 10:43, Steven Bethard <steven.bethard at gmail.com> wrote:

Not sure I follow you here. It's not the init that allows you to do x(), it's the fact that the class declares a call, right?

class C(object): ... pass ... C.call() <_main_.C object at 0x01A3C370> C() <_main_.C object at 0x02622EB0> str.call() '' str() '' I don't think so:: Foo.call <method-wrapper '_call_' of type object at 0x81cee0c> Foo.call = lambda: None Foo.call <unbound method Foo.> Foo() <_main_.Foo object at 0xf7f90e8c>

Take a look at PyObject_Call in abstract.c. Basically, call is always looked up on the type, something like:

class C(object): ... def call(self): ... return 'instance' ... def func(): ... return 'func' ... type(C).call(C) <__main__.C object at 0x0263E250> type(C()).call(C()) 'instance' type(func).call(func) 'func'

Steve

I'm not in-sane. Indeed, I am so far out of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy



More information about the Python-Dev mailing list