Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: =?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?= Newsgroups: comp.lang.python Subject: Re: Multiple inheritance, super() and changing signature Date: Fri, 3 Jun 2016 16:06:12 +0200 Lines: 85 Message-ID: References: <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de 4MBFCGUQcBK38ZBMkNnUGwD/mxI1Vi/2eOd+Xmj6UF5Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.058 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'modified': 0.05; 'classes.': 0.07; '__init__': 0.09; 'argument:': 0.09; 'positional': 0.09; 'typeerror:': 0.09; 'def': 0.13; 'received:io': 0.16; 'received:psf.io': 0.16; 'result:': 0.16; 'root:': 0.16; 'subject:changing': 0.16; 'sure.': 0.16; 'pass': 0.22; 'this:': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'signatures': 0.29; 'classes': 0.30; 'code': 0.30; 'becomes': 0.30; 'raymond': 0.30; 'skip:_ 10': 0.32; 'class': 0.33; 'traceback': 0.33; 'changing': 0.34; 'file': 0.34; 'could': 0.35; 'skip:s 60': 0.35; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'missing': 0.37; 'self': 0.38; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'easy': 0.60; 'share': 0.61; 'watch': 0.62; 'charset:windows-1252': 0.62; 'url:png': 0.64; '20,': 0.66; 'url:26': 0.66; 'here': 0.66; 'url:2011': 0.75; 'url:i': 0.77; 'completion': 0.79; 'url:wordpress': 0.79; 'url:imgur': 0.84; 'shows,': 0.91; 'cooperative': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopzeus.com; s=shopzeus_com; t=1464962772; bh=IUDfiekzisFQptedAJEmd8sM2oAdSiPGkxfk8J99TJI=; h=Subject:To:References:From:Date:In-Reply-To:From; b=eS5zbNZzEDKd7Gbc4ZWHa0Z8HCyOHZ/Ka8HLatV1/zjL76Yt2sFiiKDgP+5NG6sV4 4afHb7IxUAvPKBmTqdVp2DrXyQHejbHXjuC1CBEbNF/19gC2/oxTdknUrY3CLscCYI BOMRkCdsf8J2DQR5K4yDrzRnX8Jw+jitTDD+nk5belCaMVHZK4D0tqBUAmQJ6wFo7M P3B/Mxhvx26mVgmOSb3ynBglkAaa6DB07MkgTYFQIDpVDyneLmrTmul1v/JQyTJyTi InaHXL4vnhtavPaY3POnsIAvgc3yHQ0yri5QxWzFp1zwCvXZIiCvi+xHLCshuPlNxS +VpuAHLV/yKgA== In-Reply-To: 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: 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:109414 >> That's overly strict. As Raymond shows, it is easy to deal with >> changing method signatures in *cooperative* classes.=20 > I must watch that for sure. All right, I have read this: https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ There is still something I don't get: how to create cooperative classes when some base classes share some of the parameters? Here is an example modified from Raymond's post: class A: def __init__(self, param1, param2, **kwds): self.param1 =3D param1 self.param2 =3D param2 super().__init__(**kwds) class B: def __init__(self, param1, param3, **kwds): self.param1 =3D param1 self.param3 =3D param3 super().__init__(**kwds) class X(A,B): def __init__(self, param1, param2, param3, **kwds): print("param1=3D",param1,"param2=3D",param2,"param3=3D",param3) super().__init__(param1=3Dparam1,param2=3Dparam2,param3=3Dparam3,= **kwds) print(X.__mro__) x =3D X(1,2,3) Result: (, , , ) param1=3D 1 param2=3D 2 param3=3D 3 Traceback (most recent call last): File "test.py", line 20, in x =3D X(1,2,3) File "test.py", line 17, in __init__ super().__init__(param1=3Dparam1,param2=3Dparam2,param3=3Dparam3,**kw= ds) File "test.py", line 5, in __init__ super().__init__(**kwds) TypeError: __init__() missing 1 required positional argument: 'param1' I could only find this as a solution: class Root: def __init__(self, **kwds): pass class A(Root): def __init__(self, **kwds): self.param1 =3D kwds['param1'] self.param2 =3D kwds['param2'] super().__init__(**kwds) class B(Root): def __init__(self, **kwds): self.param1 =3D kwds['param1'] self.param3 =3D kwds['param3'] super().__init__(**kwds) class X(A,B): def __init__(self, param1, param2, param3, **kwds): print("param1=3D",param1,"param2=3D",param2,"param3=3D",param3) super().__init__(param1=3Dparam1,param2=3Dparam2,param3=3Dparam3,= **kwds) X(1,2,3) But then self documentation and code completion becomes very problematic:= http://i.imgur.com/wzlh8uy.png