package extension problem

Jerry Hill malaclypse2 at gmail.com
Mon Feb 13 19:00:52 CET 2012


On Sun, Feb 12, 2012 at 1:46 PM, Fabrizio Pollastri <f.pollastri at inrim.it>wrote:

> Hello,
>
> I wish to extend the functionality of an existing python package by
> creating
> a new package that redefines the relevant classes of the old package. Each
> new class inherits the equivalent old class and adds new methods.
> ...

There is a way to solve this problem without redefining in the new package
> all the
> methods of the old package that return old classes?
>

The general answer is no.  If you want the methods of your subclass to
behave differently, in any way, from the same methods in the superclass,
then you must write new code that defines the behavior that you want.

Sometimes people write their classes so they automatically play nicely when
subclassed, and sometimes they don't.  In general, it's impossible to
always do the right thing when you don't know what particular behavior a
subclass might need to override, so a lot of times people don't bother to
write their classes to check for subclasses being passed in, etc.

Since you haven't actually shown us any code, that's about all I can tell
you.

-- 
Jerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120213/ec81a8c8/attachment.html>


More information about the Python-list mailing list