Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'example:': 0.03; 'package,': 0.03; 'imports': 0.07; 'python': 0.08; 'classes?': 0.09; 'package.': 0.12; 'subject:package': 0.16; 'advance': 0.17; 'instance': 0.18; 'subject:problem': 0.19; 'dictionary': 0.23; 'creating': 0.25; 'classes': 0.26; 'import': 0.27; 'class': 0.29; 'problem': 0.29; 'equivalent': 0.31; 'adds': 0.32; 'thanks': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.35; '...': 0.35; 'something': 0.35; 'extend': 0.36; 'hello,': 0.37; 'some': 0.38; 'to:addr:python.org': 0.40; 'wish': 0.68; 'relevant': 0.71; 'fabrizio': 0.84; 'following.': 0.91; 'received:2': 0.91; 'redefining': 0.91 X-Virus-Scanned: amavisd-new at sisrv6.intra.inrim.it Date: Sun, 12 Feb 2012 19:46:04 +0100 From: Fabrizio Pollastri User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16 MIME-Version: 1.0 To: python-list@python.org Subject: package extension problem Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1329072778 news.xs4all.nl 6971 [2001:888:2000:d::a6]:34524 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20286 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. In the new package there is something like the following. import old_package as op class A(op.A): ... add new methods ... class B(op.B): ... add new methods ... Some classes of the old package works as a dictionary of other classes of the same old package. Example: if class A and class B are classes of the old package, B[some_hash] returns an instance of A. When a program imports the new package and create instances of the new class B, B[some_hash] still returns an instance of the old class A, while I want an instance of the new class A. 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? Thanks in advance for any suggestion, Fabrizio