Pure virtual functions in Python?

lallous elias.bachaalany at gmail.com
Thu Feb 25 13:25:14 CET 2010


On Feb 21, 11:21 am, Lie Ryan <lie.1... at gmail.com> wrote:
> On 02/21/10 19:27,lallouswrote:
> <snip>
>
> > If the base defines the method and it was empty, then my C++ code
> > would still call the function. This is not optimal because I don't
> > want to go from C++ to Python if the _derived_ class does not
> > implement the cb.
>
> That sounds like a microoptimization; have you profiled your code and
> determined that calling empty function causes a bottleneck? I doubt it.
>
> > Now the base class should define it so that doc
> > parsers properly describe the base class.
> > The recipe suggested is not worth the trouble.
> > Unfortunately I cannot use abc module since I use Python 2.5
>
> Because nobody here could have guessed that your dispatcher was written
> in C++; your problem is near trivial if your dispatcher is a pure-python
> code.

You are right. I haven't checked how much it costs to continuously
call an empty function, but why do it if I know (during initialization
from my C++ dispatcher code) that certain Python object should not
have certain methods called.

I still prefer not to call at all, even if it was an empty function.

Regards,
Elias



More information about the Python-list mailing list