Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder4.news.weretis.net!storethat.news.telefonica.de!feedme.news.telefonica.de!telefonica.de!fu-berlin.de!uni-berlin.de!not-for-mail From: dieter Newsgroups: comp.lang.python Subject: Re: Making Classes Subclassable Date: Mon, 04 Jul 2016 09:57:27 +0200 Lines: 7 Message-ID: References: <87eg79q1i0.fsf@handshake.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-7 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de 8Mbtq9kfRu7jaQGzrCGDVwiCgB9gGZ/nsFVIsAoaSLIQ== Cancel-Lock: sha1:HBNLHBq5T68FNQwHv9UMLd5JkbQ= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'inherited': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:github': 0.09; '<>.': 0.11; 'charset:iso-8859-7': 0.15; '(there': 0.16; 'elsewhere,': 0.16; 'means.': 0.16; 'objects;': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subclassing': 0.16; 'subject:Classes': 0.16; 'lawrence': 0.22; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X -Complaints-To:1': 0.26; 'classes': 0.30; 'class.': 0.30; 'operations': 0.31; 'class': 0.33; 'instances': 0.33; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'means': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'more': 0.63; 'binding': 0.66; 'reuse': 0.66; 'indirect': 0.84; 'subject:Making': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57b38ea7.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <87eg79q1i0.fsf@handshake.de> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:111049 Lawrence D˘Oliveiro writes: > Some of the classes in Qahirah, my Cairo binding I found handy to reuse elsewhere, for example in my binding for Pixman . Subclassing is easy, but then you need to ensure that operations inherited from the superclass return instances of the right class. This means that superclass methods must never refer directly to the class by name for constructing new objects; they need to obtain the current class by more indirect means. --> "type(obj)" or "obj.__class__" (there are small differences) give you the type/class of "obj".