Re: callable virtual method

2009-08-17 Thread Bruno Desthuilliers
Jean-Michel Pichavant a écrit : (snip) Sometimes the base is doing cool stuff but incomplete stuff which requires knowledge only hold by the sub class. In my case the interface is a high level interface for a software that can run on multiple hardware platforms. Only the sub class has

Re: callable virtual method

2009-08-17 Thread Bruno Desthuilliers
Jean-Michel Pichavant a écrit : Scott David Daniels wrote: (snip) But there _is_ one moment when you can check those things, then avoid checking thereafter: object creation. So you can complicate your __init__ (or __new__) with those checks that make sure you instantiate only fully defined

Re: callable virtual method

2009-08-16 Thread Jean-Michel Pichavant
Scott David Daniels wrote: Jean-Michel Pichavant wrote: Steven D'Aprano wrote: On Fri, 14 Aug 2009 18:49:26 +0200, Jean-Michel Pichavant wrote: Sorry guys (means guys *and* gals :op ), I realized I've not been able to describe precisely what I want to do. I'd like the base class to be

Re: callable virtual method

2009-08-16 Thread Christian Heimes
Jean-Michel Pichavant wrote: scott.dani...@acm.org That could do the trick, sparing me from writing additional code in each methods. Thanks. Why are you trying to reinvent the wheel? Python's abc module already takes care of these details. Christian --

Re: callable virtual method

2009-08-16 Thread Jean-Michel Pichavant
Christian Heimes wrote: Jean-Michel Pichavant wrote: talking about approaches: 1/ class Interface: def foo(self): if self.__class__.foo == Interface.foo: raise NotImplementedError 2/ class Interface: def foo(self): self._foo() def _foo(sef): raise

Re: callable virtual method

2009-08-16 Thread jean-michel Pichavant
Christian Heimes a écrit : Jean-Michel Pichavant wrote: scott.dani...@acm.org That could do the trick, sparing me from writing additional code in each methods. Thanks. Why are you trying to reinvent the wheel? Python's abc module already takes care of these details. Christian I'm working

Re: callable virtual method

2009-08-15 Thread Scott David Daniels
Jean-Michel Pichavant wrote: Steven D'Aprano wrote: On Fri, 14 Aug 2009 18:49:26 +0200, Jean-Michel Pichavant wrote: Sorry guys (means guys *and* gals :op ), I realized I've not been able to describe precisely what I want to do. I'd like the base class to be virtual (aka abstract). However

callable virtual method

2009-08-14 Thread Jean-Michel Pichavant
Hi fellows, Does anyone know a way to write virtual methods (in one virtual class) that will raise an exception only if called without being overridden ? Currently in the virtual method I'm checking that the class of the instance calling the method has defined that method as well. Example:

Re: callable virtual method

2009-08-14 Thread MRAB
Jean-Michel Pichavant wrote: Hi fellows, Does anyone know a way to write virtual methods (in one virtual class) that will raise an exception only if called without being overridden ? Currently in the virtual method I'm checking that the class of the instance calling the method has defined

Re: callable virtual method

2009-08-14 Thread Diez B. Roggisch
Jean-Michel Pichavant schrieb: Hi fellows, Does anyone know a way to write virtual methods (in one virtual class) that will raise an exception only if called without being overridden ? Currently in the virtual method I'm checking that the class of the instance calling the method has defined

Re: callable virtual method

2009-08-14 Thread Steven D'Aprano
On Fri, 14 Aug 2009 16:49:47 +0200, Jean-Michel Pichavant wrote: Hi fellows, Does anyone know a way to write virtual methods (in one virtual class) that will raise an exception only if called without being overridden ? Currently in the virtual method I'm checking that the class of the

Re: callable virtual method

2009-08-14 Thread Jean-Michel Pichavant
MRAB wrote: Jean-Michel Pichavant wrote: Hi fellows, Does anyone know a way to write virtual methods (in one virtual class) that will raise an exception only if called without being overridden ? Currently in the virtual method I'm checking that the class of the instance calling the method

Re: callable virtual method

2009-08-14 Thread Diez B. Roggisch
Jean-Michel Pichavant schrieb: MRAB wrote: Jean-Michel Pichavant wrote: Hi fellows, Does anyone know a way to write virtual methods (in one virtual class) that will raise an exception only if called without being overridden ? Currently in the virtual method I'm checking that the class of

Re: callable virtual method

2009-08-14 Thread Jean-Michel Pichavant
Diez B. Roggisch wrote: Jean-Michel Pichavant schrieb: MRAB wrote: Jean-Michel Pichavant wrote: Hi fellows, Does anyone know a way to write virtual methods (in one virtual class) that will raise an exception only if called without being overridden ? Currently in the virtual method I'm

Re: callable virtual method

2009-08-14 Thread Nigel Rantor
Jean-Michel Pichavant wrote: Your solution will work, for sure. The problem is that it will dumb down the Base class interface, multiplying the number of methods by 2. This would not be an issue in many cases, in mine there's already too much meaningful methods in my class for me to add

Re: callable virtual method

2009-08-14 Thread Steven D'Aprano
On Fri, 14 Aug 2009 18:49:26 +0200, Jean-Michel Pichavant wrote: Sorry guys (means guys *and* gals :op ), I realized I've not been able to describe precisely what I want to do. I'd like the base class to be virtual (aka abstract). However it may be abstract but it does not mean it cannot do

Re: callable virtual method

2009-08-14 Thread Jean-Michel Pichavant
Nigel Rantor wrote: Jean-Michel Pichavant wrote: Your solution will work, for sure. The problem is that it will dumb down the Base class interface, multiplying the number of methods by 2. This would not be an issue in many cases, in mine there's already too much meaningful methods in my

Re: callable virtual method

2009-08-14 Thread Nigel Rantor
Jean-Michel Pichavant wrote: Nigel Rantor wrote: Jean-Michel Pichavant wrote: Your solution will work, for sure. The problem is that it will dumb down the Base class interface, multiplying the number of methods by 2. This would not be an issue in many cases, in mine there's already too

Re: callable virtual method

2009-08-14 Thread Dave Angel
Jean-Michel Pichavant wrote: div class=moz-text-flowed style=font-family: -moz-fixedNigel Rantor wrote: Jean-Michel Pichavant wrote: Your solution will work, for sure. The problem is that it will dumb down the Base class interface, multiplying the number of methods by 2. This would not be

Re: callable virtual method

2009-08-14 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Fri, 14 Aug 2009 18:49:26 +0200, Jean-Michel Pichavant wrote: Sorry guys (means guys *and* gals :op ), I realized I've not been able to describe precisely what I want to do. I'd like the base class to be virtual (aka abstract). However it may be abstract but it

Re: callable virtual method

2009-08-14 Thread Jean-Michel Pichavant
Dave Angel wrote: Jean-Michel Pichavant wrote: div class=moz-text-flowed style=font-family: -moz-fixedNigel Rantor wrote: Jean-Michel Pichavant wrote: Your solution will work, for sure. The problem is that it will dumb down the Base class interface, multiplying the number of methods by 2.

Re: callable virtual method

2009-08-14 Thread Christian Heimes
Jean-Michel Pichavant wrote: talking about approaches: 1/ class Interface: def foo(self): if self.__class__.foo == Interface.foo: raise NotImplementedError 2/ class Interface: def foo(self): self._foo() def _foo(sef): raise NotImplementedError