Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Selik Newsgroups: comp.lang.python Subject: Re: Overriding methods inherited from a superclass with methods from a mixin Date: Mon, 13 Jun 2016 22:50:50 +0000 Lines: 69 Message-ID: References: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> <0aabc4bb-8939-45b8-9a70-7023cf434a05@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de j8ogfcQxRSPhNAG091LFKAvoX381MnURz5zcATpZ423Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'root': 0.04; 'definitions.': 0.07; 'python': 0.10; '(at': 0.13; 'subject: \n ': 0.15; '2016': 0.16; 'bases,': 0.16; 'correctly,': 0.16; 'hierarchy': 0.16; 'inheritance': 0.16; 'intuition': 0.16; 'kinds,': 0.16; 'left,': 0.16; 'lookups': 0.16; 'mistake.': 0.16; 'prioritizing': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sense,': 0.16; 'still,': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'implementing': 0.18; 'tree': 0.18; '>': 0.18; 'email addr:gmail.com>': 0.18; 'to:2**1': 0.21; 'java': 0.22; 'bit': 0.23; 'seems': 0.23; 'interfaces': 0.23; "haven't": 0.24; 'thus': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'sense': 0.26; 'right.': 0.27; 'to:no real name:2**1': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'specify': 0.27; 'correct': 0.28; 'fine': 0.28; '13,': 0.29; 'mind,': 0.29; 'quoting': 0.29; 'thinks': 0.29; 'selection': 0.29; "i'm": 0.30; 'classes': 0.30; 'code': 0.30; 'post': 0.31; 'anyone': 0.32; 'class': 0.33; 'point,': 0.33; 'languages': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'fail': 0.35; 'quite': 0.35; 'something': 0.35; "isn't": 0.35; 'but': 0.36; 'list,': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; '(and': 0.36; "wasn't": 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'method': 0.37; 'list.': 0.37; 'doing': 0.38; 'received:209': 0.38; 'someone': 0.38; 'thank': 0.38; 'mailing': 0.38; 'mean': 0.38; 'received:209.85.220': 0.38; 'google': 0.39; 'sure': 0.39; 'url:en': 0.39; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'subject:with': 0.40; 'some': 0.40; 'your': 0.60; 'video': 0.62; 'providing': 0.62; 'bases': 0.63; 'more': 0.63; 'articles': 0.67; 'url:v': 0.72; 'url:youtube': 0.73; 'url:watch': 0.78; '"most': 0.84; '*no': 0.84; 'metaphor': 0.84; 'one*': 0.84; 'people"': 0.84; 'plugins': 0.84; 'replies.': 0.84; 'top.': 0.84; 'from.': 0.93; 'ranked': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=MiRth7oODwyOHdPNEcSh4LwkX0tue4FZCHzZ0yvFhL4=; b=nQn2lf2vkiXelCv7B4k+KWF9MWuEmE7G2hkfxGkfQCTglbiUKfQsWXGM8sS5/dk8x6 wSL60OqkDK5xfxF0wmfOO7ZYCy3A6QKBeEHo8El9RjDM0qxNEktR5UV76kL6jTFHvT9y GOSq+xO9wLgj4QPBsC+Df/DZV/M9Q95mzTLcnQAFSDjcvu0VYOKuz/UYQ3CrtzcF4ERl RjDvZqlhI0C70UDnQ8JP7WPUbP6UeR/e7kOfP5bDwWu/aVuyUVaRJu67bH/MIJmyyDfj fIZjfeiVTCPKudTYTxZE9WZrU2yJWtfTgzisuGHwtybyekTwWv7Skvv6eWvg9PDov+Q1 z/6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=MiRth7oODwyOHdPNEcSh4LwkX0tue4FZCHzZ0yvFhL4=; b=Lst9Tm3/jxE7vlnJJqQRkKkn7gQlg3/rthRyZLbuTE43jZ7z902BQzUHfLxe3Twa98 kOgLNoHLLpQ/UIBgyFvVJcW0vY8WeGjgB6ykcVgJbVDBl3EPRwb9ow1TdLwfoyzc/EMK 9zWNjg5/S5WJ3kfcmaLBYXA2oMBeT9KNmdGLkcScDx4rX7/hI5q3K8AIUnXP6yHLpGAU bgNxaEu34OuE7Gs56PlxHYSLgbC1ykhRPIIP+JAXQefK4akPHz3MIoLSKwkMMlbOaLz/ kY+jgFjY6hfY46xtR9oRsF7sJITUQ5kY/2FgwT2jugMm1IjjhAIKgQDacY0ARt8ZpIaY ZH7Q== X-Gm-Message-State: ALyK8tKnm+JjavxBrXNkaO9DBxrNHX1wJyNg9dVXaI2YPDAwbmyg5ODNc7jJOObqmXOljrKcc0K0PmSrog9RDQ== X-Received: by 10.55.144.68 with SMTP id s65mr16830846qkd.209.1465858260347; Mon, 13 Jun 2016 15:51:00 -0700 (PDT) In-Reply-To: <0aabc4bb-8939-45b8-9a70-7023cf434a05@googlegroups.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.22 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: <2a1088f1-3bdb-4b21-80b5-8cc640d3bceb@googlegroups.com> <0aabc4bb-8939-45b8-9a70-7023cf434a05@googlegroups.com> Xref: csiph.com comp.lang.python:109913 On Mon, Jun 13, 2016 at 2:46 PM wrote: > Thank you for your replies. I don't know if I'm quoting you correctly, I'm > quite confused with Google Groups... not sure if it's a "forum", something > like a mailing list, or both... or neither. > Mailing list. A "forum" in the metaphorical sense, not the sense of phpBB. You're doing fine with quoting, though it would help to add who said what when quoting multiple people. since the correct order is from right to left, Did you mean left-to-right? Are you thinking of Java where there's only one parent class allowed and you specify any extra interfaces you're implementing afterwards? Because that's not what your code is doing. Still, pretty much *no one* uses that order [mixin1, mixin2, base]. A quick > Google search returns (at least in my "bubble") many blog articles from > "notable" Python users with that order wrong. > Do you mind providing links? I haven't seen anyone "notable" make this mistake. > > To me it makes sense. English reads left-to-right, so method > > lookups go left-to-right (and children before parents) in the inheritance > > list. > > Basically I wasn't very confident the code was OK because my intuition > said the right way to order the classes I was inheriting from was from left > to right. That is correct! Write them in the order you are prioritizing the definitions. Overrides before bases, left to right. > I don't see any sense in that analogy you made... sure English and most > occidental languages read ltr, but I fail to see how it makes more sense to > have the base class on the right and the mixins on the left. Basically, I > think of the mixins like plugins of kinds, I'm "adding" functionality to > that "base" class I'm inheriting from. That's not a good metaphor for what's actually happening. For more detail, check out Raymond's "super considered super" video ( https://www.youtube.com/watch?v=EiOglTERPEo). > Don't take my word for it, Google multi inheritance or mixin in Python and > let me know if you find someone who thinks it's "natural" to do it that way. This might be a bit of selection bias. People who think it makes sense might not have an incentive to write a blog post about it. People who don't like it will thus be more vocal. Ian Lewis seems to be ranked highly by Google ( https://www.ianlewis.org/en/mixins-and-python). I disagree with his assertion that "most people" read an inheritance hierarchy top-down with the bases at the left. I think of inheritance as a tree. Even if it is a diamond at some point, a depth-first-search of a tree isn't far off from the truth. The root (base) is at the bottom, in my mind, and the leaves are at the top.