Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: Multiple inheritance, super() and changing signature Date: Fri, 03 Jun 2016 22:21:22 +1000 Lines: 39 Message-ID: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <85k2i65upp.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de gY+hwQb8SryOP0/K2TtYvAoqQwBz+mrfg9AKcPUb91VQ== Cancel-Lock: sha1:vrxkuo7lTHj7zUN2F1+Kp66Xw1Q= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'initialize': 0.05; 'bootstrap': 0.07; 'false.': 0.07; '__init__': 0.09; 'behave': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:releases': 0.09; 'python': 0.10; 'useful,': 0.13; 'def': 0.13; 'do,': 0.15; 'attributes.': 0.16; 'hierarchy,': 0.16; 'inheritance': 0.16; 'mutliple': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:changing': 0.16; 'url:mro': 0.16; 'widget': 0.18; 'arguments': 0.22; 'leave': 0.23; 'skip:b 30': 0.24; 'all.': 0.24; 'url:download': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'define': 0.27; 'connects': 0.27; 'correct': 0.28; 'classes': 0.30; 'that.': 0.30; 'raymond': 0.30; 'guess': 0.31; "can't": 0.32; 'skip:_ 10': 0.32; 'statement': 0.32; 'class': 0.33; 'url:python': 0.33; 'covered': 0.34; 'that,': 0.34; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'url:3': 0.60; 'your': 0.60; 'default': 0.61; 'here:': 0.63; 'places': 0.64; 'skip:\xe2 10': 0.70; '8bit%:43': 0.72; '_o__)': 0.84; 'nagy': 0.84; 'received:125': 0.84; 'upset': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/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: <85k2i65upp.fsf@benfinney.id.au> X-Mailman-Original-References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:109407 Nagy László Zsolt writes: > > [...] > >> class BootstrapDesktop(BootstrapWidget, BaseDesktop): > >> def __init__(self, appserver, session): > >> # there is NOTHING else here, it just connects bootstrap widget > >> implementation with desktop methods > >> super(BootstrapDesktop, self).__init__(appserver, session) > > The correct way to do that is to simply not define an __init__ method at > > all. > But I have to initialize some default attributes. Then the statement “there is NOTHING else here” must be false. Either the custom ‘__init__’ does something useful, or it doesn't. > > See this explanation of C3 linearisation here: > > > > https://www.python.org/download/releases/2.3/mro/ > I do not use diamond shapes in my hierarchy, I guess that does not > affect me. I may be wrong. With classes all inheriting ultimately from ‘object’ (as all Python 3 classes do, and as all current Python 2 classes should), mutliple inheritance inevitably places your classes in a diamond inheritance pattern. And, what's more, you can't know when writing a class whether it participates in a multiple inheritance hierarchy! So in practice you must write every class so that it will behave well in a diamond inheritance pattern. All this is covered in Raymond Hettinger's material, so it's best that I just leave you to read that. -- \ “If the arguments in favor of atheism upset you, explain why | `\ they’re wrong. If you can’t do that, that’s your problem.” | _o__) —Amanda Marcotte, 2015-02-13 | Ben Finney