[Numpy-discussion] Where does _assert_func come from.
Charles R Harris
Thu Aug 28 21:07:56 CDT 2008
On Thu, Aug 28, 2008 at 7:54 PM, Fernando Perez <email@example.com>wrote:
> On Thu, Aug 28, 2008 at 6:39 PM, Charles R Harris
> <firstname.lastname@example.org> wrote:
> > Turns out it's defined in a derived class, which I suppose makes it a
> > class. Looks kinda like the python version of pure virtual functions in
> > base classes. It's a bit surprising to see a python pattern that's more
> > obscure than C++ ;) I'm not sure I like its usage here -- implementation
> > rather than is a -- but I'm not going to clean it up.
> The typical way to do this in python would be to write in the base
> class you saw:
> def assert_func(self,a,b):
> "some explanation"
> raise NotImplementedError
> this makes the desired interface explicit, while indicating that the
> method is meant to be implemented by subclasses. In a multiple
> inheritance situation, however, this may be a bad idea if the class is
> meant to be mixed with another that provides the method (because it
> could overwrite the real one, depending on how the inheritance diagram
> is set up).
> In summary, my take on this is:
> - if it's meant to be an abstract base class that declares an
> interface, use the idiom above for clarity.
> - if you're writing a mixin meant to be overlaid on top of another
> class with a specific interface like this, then at the very least
> document that fact very well in the code.
> Just my 1e-2,
Thanks. It's always nice to learn something new.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion