Re: Pure virtual functions in Python?

2010-02-25 Thread lallous
On Feb 21, 11:21 am, Lie Ryan lie.1...@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

Re: Pure virtual functions in Python?

2010-02-25 Thread lallous
On Feb 22, 12:42 am, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: lallouswrote: 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

Re: Pure virtual functions in Python?

2010-02-25 Thread Jean-Michel Pichavant
lallous wrote: I still prefer not to call at all, even if it was an empty function. Regards, Elias Is there any way we could convince you that there is no point caring about this ? Even if you were trying to optimize speed, it would still require proof that an empty function is part of

Re: Pure virtual functions in Python?

2010-02-25 Thread Aahz
In article 38ddd614-583c-430d-b998-214bd6360...@b2g2000yqi.googlegroups.com, lallous elias.bachaal...@gmail.com wrote: On Feb 22, 12:42=A0am, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: lallouswrote: If the base defines the method and it was empty, then my C++ code would still call the

Re: Pure virtual functions in Python?

2010-02-24 Thread Jean-Michel Pichavant
Arnaud Delobelle wrote: lallous elias.bachaal...@gmail.com writes: Hello How can I do something similar to pure virtual functions in C++ ? Let us consider this: class C1: # Pure virtual def cb(self, param1, param2): This is a callback @param param1: ...

Re: Pure virtual functions in Python?

2010-02-21 Thread lallous
On Feb 20, 6:08 pm, Martin v. Loewis mar...@v.loewis.de wrote: class C1:      # Pure virtual      def cb(self, param1, param2):                    This is a callback         �...@param param1: ...         �...@param param2: ...                    raise NotImplementedError,

Re: Pure virtual functions in Python?

2010-02-21 Thread lallous
Thanks everyone for the answers. The dispatcher() is actually sits in C++ code. So my code receives an object that is an instance of the base class, it PyObject_GetAttrString(py_obj, 'funcname'). If the attribute exists I will call PyObject_CallMethod on it. If the base defines the method and

Re: Pure virtual functions in Python?

2010-02-21 Thread Martin v. Loewis
That's not true. Currently, the hasattr() call would report that cb is available, when it is actually not implemented. It would be possible to do something like if hasattr(c, 'cb') and not is_pure(c.cb): c.cb(Hello, World) is_pure could, for example, look at a function attribute of

Re: Pure virtual functions in Python?

2010-02-21 Thread Lie Ryan
On 02/21/10 19:27, lallous wrote: 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;

Re: Pure virtual functions in Python?

2010-02-21 Thread Gregory Ewing
lallous wrote: 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. I would simply not implement the method at all in the base class.

Re: Pure virtual functions in Python?

2010-02-20 Thread Martin v. Loewis
lallous wrote: Hello How can I do something similar to pure virtual functions in C++ ? See, for example http://code.activestate.com/recipes/266468/ Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Pure virtual functions in Python?

2010-02-20 Thread Diez B. Roggisch
Am 20.02.10 17:12, schrieb lallous: Hello How can I do something similar to pure virtual functions in C++ ? Let us consider this: class C1: # Pure virtual def cb(self, param1, param2): This is a callback @param param1: ... @param param2: ...

Re: Pure virtual functions in Python?

2010-02-20 Thread Martin v. Loewis
class C1: # Pure virtual def cb(self, param1, param2): This is a callback @param param1: ... @param param2: ... raise NotImplementedError, Implement me # Dispatcher function that calls 'cb' only if 'cb' is implemented

Re: Pure virtual functions in Python?

2010-02-20 Thread Diez B. Roggisch
Sorry, I totally mis-read the OP, too tired. You are right of course. Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: Pure virtual functions in Python?

2010-02-20 Thread Rami Chowdhury
On Saturday 20 February 2010 11:46:42 Diez B. Roggisch wrote: Am 20.02.10 17:12, schrieb lallous: Hello How can I do something similar to pure virtual functions in C++ ? Let us consider this: class C1: # Pure virtual def cb(self, param1, param2):

Re: Pure virtual functions in Python?

2010-02-20 Thread Peter Otten
lallous wrote: How can I do something similar to pure virtual functions in C++ ? http://docs.python.org/library/abc.html#abc.abstractmethod Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: Pure virtual functions in Python?

2010-02-20 Thread I V
On Sat, 20 Feb 2010 08:12:01 -0800, lallous wrote: How can I do something similar to pure virtual functions in C++ ? From what you want, it seems like you want cb() to not be called if it isn't implemented in the derived class; this isn't really what pure virtual functions in C++ do - pure

Re: Pure virtual functions in Python?

2010-02-20 Thread Arnaud Delobelle
lallous elias.bachaal...@gmail.com writes: Hello How can I do something similar to pure virtual functions in C++ ? Let us consider this: class C1: # Pure virtual def cb(self, param1, param2): This is a callback @param param1: ... @param