Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail 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; '(at': 0.03; 'method,': 0.05; 'skip:` 10': 0.07; '===': 0.09; '[1]:': 0.09; '[2]:': 0.09; '[3]:': 0.09; 'argument,': 0.09; 'arguments,': 0.09; 'be:': 0.09; 'bind': 0.09; 'least)': 0.09; 'oh,': 0.09; 'subclass': 0.09; 'subject:method': 0.09; 'being,': 0.16; 'considers': 0.16; 'footnotes': 0.16; 'ignores': 0.16; 'two.': 0.16; 'cc:addr:python- list': 0.16; '(i.e.': 0.17; 'wrote:': 0.18; 'instance': 0.18; 'cheers,': 0.20; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'subject:use': 0.24; 'received:209.85.220': 0.25; 'cc:2**0': 0.26; 'tried': 0.27; 'message-id:@mail.gmail.com': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'url:wiki': 0.29; 'chris': 0.30; 'error': 0.30; 'equivalent': 0.31; 'subject:?': 0.31; 'actually': 0.31; 'thu,': 0.32; 'does': 0.32; "isn't": 0.33; 'it.': 0.33; 'it?': 0.33; 'object': 0.33; 'thank': 0.35; 'be.': 0.35; 'passed': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'happens': 0.38; 'skip:_ 10': 0.38; 'received:209.85': 0.38; 'uses': 0.38; 'useful': 0.38; 'getting': 0.38; 'third': 0.38; 'returned': 0.39; 'clearly': 0.39; 'difficult': 0.39; 'received:209': 0.39; 'put': 0.40; 'john': 0.61; 'header:Received:6': 0.61; 'your': 0.61; 'here': 0.64; 'url:cgi': 0.68; '[3]': 0.73; 'subject:this': 0.74; 'contrast,': 0.84; 'grabs': 0.84; 'sender:addr:chris': 0.84; 'url:rebertia': 0.84; 'magical': 0.93 Received-SPF: pass (google.com: domain of chris@rebertia.com designates 10.52.28.76 as permitted sender) client-ip=10.52.28.76; Authentication-Results: mr.google.com; spf=pass (google.com: domain of chris@rebertia.com designates 10.52.28.76 as permitted sender) smtp.mail=chris@rebertia.com; dkim=pass header.i=chris@rebertia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=TQ4SZkjEhClpTUJqRTRNmbQFKfGoefHu1m0TTGzGTic=; b=MVCM04V1lhEMO+qTTi9R9sPyZdPc6PGQpLMs2+CX/X31HG6mDYD37/vAOiZLgoPsew z/Wr9aN0ON/bRGGoCEF2ZhESkAX5dWJ01pIbL2ioAJVXcRrU3hpepAmRK6HDo9eM2xoy wnfbL3NuovMHjtVC43cSg3ba748B+w8FGPPDU= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Date: Fri, 2 Mar 2012 00:08:17 -0800 X-Google-Sender-Auth: qEU0AbClYKNtk1fY7KQvveZHZ9k Subject: Re: Is this the proper way to use a class method? From: Chris Rebert To: John Salerno Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQly1jRs14VXybRaxNRYDztTHgd/VuAiqwUrclv2UwM2wXEhC39PgGS0xLGq1px9GcMxwN/r Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1330675701 news.xs4all.nl 6947 [2001:888:2000:d::a6]:44662 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21131 On Thu, Mar 1, 2012 at 11:16 PM, John Salerno wrote: >> That's just a coincidence. Your supercall is ought to be: super().move() >> In contrast, super().move(self) calls the superclass instance method >> `move` with 2 arguments, both `self`, which just happens to work given >> your move() method, inside which `cls` isn't actually a class like it >> ought to be. > > Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. > > But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? The instance of the subclass (i.e. what Pawn.move() considers `self`) gets passed to it. > How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? Oh, but it does get passed, just implicitly. `super()` basically grabs `self` magically from its caller, and uses it to bind method calls on the magical object returned by `super()`. `super().move()` ends up being, in this particular case, equivalent to: ChessPiece.move(self) which is incidentally how one would write this without using super(). Here is a useful[1] "identity" to ponder: x.y(z) === type(x).y(x, z) Cheers, Chris -- [1]: In the sense of a useful lie[2]; it's far from completely accurate; it (at the least) ignores metaclasses, overridings of __getattribute__(), and a third thing that's difficult to clearly put into words. [2]: http://c2.com/cgi/wiki?UsefulLie [3] [3]: Yes, my footnotes have footnotes. http://rebertia.com