Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Multiple inheritance, super() and changing signature Date: Fri, 3 Jun 2016 08:39:00 -0600 Lines: 40 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=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de +GfYIdBpXRgr0onH5rSp6gxU7oW13HMDXLl4fyn1pXFA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.052 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'root': 0.04; 'classes.': 0.07; 'received:209.85.218': 0.10; 'def': 0.13; '2016': 0.16; 'b):': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'root:': 0.16; 'subject:changing': 0.16; 'sure.': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'parameter': 0.22; 'pass': 0.22; 'am,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'signatures': 0.29; 'classes': 0.30; 'raymond': 0.30; 'another': 0.32; "can't": 0.32; 'skip:_ 10': 0.32; 'class': 0.33; 'extract': 0.33; 'changing': 0.34; 'received:google.com': 0.35; 'something': 0.35; 'there': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'method': 0.37; 'received:209': 0.38; 'shared': 0.38; 'why': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'easy': 0.60; 'share': 0.61; 'watch': 0.62; 'inherit': 0.66; 'url:26': 0.66; 'url:2011': 0.75; 'url:wordpress': 0.79; 'account.': 0.80; 'nagy': 0.84; 'to:name:python': 0.84; 'shows,': 0.91; 'cooperative': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=sPFcs+F1iyVE4cy0Y6cpGgvGJk9DuwFqBfpEuoebPfA=; b=gj6FgWsfp6Ddmaqg14I/9Vf7p8Y35O+YRwFd0ORaFXKVm3Go3UoGYhFwI08gNNzAJT v1C/nQUHYL7nHo2tvIb5n4qAoNNZbYfx2fwOWu7FLgrEWbH8SivxAyWMTtkC61U5UJnt Enm/LroUCr8qf1qEeONhEJQLH2QlKsRKXQE8HqXTDAXBi/2INB61fps5PBkAWEleq/0i 6dcr6GIspBVqkeJnpIPi8TF9auvXnbpsxP0eB+HJr/If3kjQOa1GuhNkudC8mgcSuGL6 1T3Xx0qg9y4slCKZh9NFubZ3QwLvpVGAI9eWMts6P+T9JPHuTjIJDjL8HppxzSMVUzyR Jqmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=sPFcs+F1iyVE4cy0Y6cpGgvGJk9DuwFqBfpEuoebPfA=; b=ZCjikU/6OkqPP6xcPnQKRJZm37YpvsLAWeSl+7FaVULcvH5eVropfYM6SpswcuFum1 7sBxg5+IdcZsVrqT7NBTiEW58t04ioNjLKMz/EOqCjo5P9JcZ+q3qWFkOpyfhqWmEQzn tXVu9gZeAZ3VrDPEgEbSfYKUR/shr+wYA/lLj/wYbwoAqpTS7Q+Qe0gIRA4zJinR9jOZ sFDwbdwQwZJz6kFyVP4l1nNPd6ga/iGb1EuFTe7duikJ5R+fYvr7WAMDC1O2vvFVwkLB tCo87bxSSEYKHlaghnDOpVg9f5nIjY8kKvkVceNZzCxsofSgQqzaBF+zybH/UnehUi7D 4ZvA== X-Gm-Message-State: ALyK8tJM1x9LlSxKb3hz8WOqa8d+z2US8r0CjGTH+xjS91XJhUntj0mNd00Xgxw0wi2fKEYw9KN/BSNaie3DWA== X-Received: by 10.157.54.98 with SMTP id w89mr1852521otb.187.1464964781255; Fri, 03 Jun 2016 07:39:41 -0700 (PDT) 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:109418 On Fri, Jun 3, 2016 at 8:06 AM, Nagy L=C3=A1szl=C3=B3 Zsolt wrote: > >>> That's overly strict. As Raymond shows, it is easy to deal with >>> changing method signatures in *cooperative* classes. >> 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? Why do they need to share the same parameter? Part of cooperative design is that you can't really design each class in a vacuum; you need to take the other classes they might get combined with into account. Perhaps you can extract that parameter into another base class that is shared by both: class Root: def __init__(self, *, param1, **kwds): self.param1 =3D param1 super().__init__(**kwds) class A(Root): def __init__(self, *, param2, **kwds): self.param2 =3D param2 super().__init__(**kwds) class B(Root): def __init__(self, *, param3, **kwds): self.param3 =3D param3 super().__init__(**kwds) class X(A, B): pass A and B can both depend on having param1 without stomping on each other because they both inherit Root which requires it.