Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21130

Re: Is this the proper way to use a class method?

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.04; 'method,': 0.05; 'argument,': 0.09; 'arguments,': 0.09; 'be:': 0.09; 'subclass': 0.09; 'subject:method': 0.09; 'am,': 0.12; 'case.': 0.15; 'collects': 0.16; 'self)': 0.16; 'two.': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.18; 'arguments': 0.18; 'instance': 0.18; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; '(or': 0.22; 'stack': 0.24; 'subject:use': 0.24; 'cc:2**0': 0.26; 'all,': 0.27; 'tried': 0.27; 'message-id:@mail.gmail.com': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.29; 'implicitly': 0.30; 'error': 0.30; 'equivalent': 0.31; 'subject:?': 0.31; 'actually': 0.31; 'does': 0.32; "isn't": 0.33; 'there': 0.33; 'received:209.85.212': 0.33; 'it?': 0.33; 'object': 0.33; 'fri,': 0.34; 'thank': 0.35; 'be.': 0.35; 'passed': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'either': 0.37; 'happens': 0.38; 'received:209.85': 0.38; 'getting': 0.38; 'received:209': 0.39; 'called': 0.40; 'john': 0.61; 'header:Received:6': 0.61; 'your': 0.61; 'is.': 0.63; 'exact': 0.68; 'subject:this': 0.74; '12:16': 0.84; 'casting': 0.84; 'contrast,': 0.84; 'received:10.180': 0.84
Received-SPF pass (google.com: domain of ian.g.kelly@gmail.com designates 10.180.83.42 as permitted sender) client-ip=10.180.83.42;
Authentication-Results mr.google.com; spf=pass (google.com: domain of ian.g.kelly@gmail.com designates 10.180.83.42 as permitted sender) smtp.mail=ian.g.kelly@gmail.com; dkim=pass header.i=ian.g.kelly@gmail.com
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 :cc:content-type; bh=+LESpzEuybLgiQEkJZfZiyH61ngLoqkOGO38ioFpURE=; b=eROjM4Vhj4btuyyAQexX6m7j3rbM/u9DxJ86SzeADmqYIZCnremyNwee6a0yVUM1J2 Jhurwr2iEK6nrPetpFyeZtRmc44u4e3fJK8Cx3k1P07qcHm5efPknEaGjf9pJ8DOJ+s3 uzPv/CEhB456V1CMyJymaEqOMhr3HY/2pgWTp3to0I77nUxuoJyHx5p/dId6f4EbTzUX MLSVbzm8LTiwybSMTSr1JwcTU4IIQzsqXMtQzP0R9YMOIunBuSvbzEvQi0RXyd0LMDiH Sr2KJfrD3nFYS/DoArccraiONM2Tb6Aq/eQeFYAx5kJMfL1etyiJl2fyKmJQq3t6Sebt jbPw==
MIME-Version 1.0
In-Reply-To <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13>
References <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <mailman.339.1330669514.3037.python-list@python.org> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Fri, 2 Mar 2012 01:04:22 -0700
Subject Re: Is this the proper way to use a class method?
To John Salerno <johnjsal@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.344.1330675495.3037.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330675495 news.xs4all.nl 6930 [2001:888:2000:d::a6]:42457
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21130

Show key headers only | View raw


On Fri, Mar 2, 2012 at 12:16 AM, John Salerno <johnjsal@gmail.com> 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 self that gets passed into the superclass.move() or the
subclass.move() is the exact same object in either case.  There is no
"up-casting" (or any casting at all, for that matter) in Python.

> How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally?

super() called without arguments is equivalent to super(<class this
method was defined in>, self) -- it collects the value of self from
the current stack frame.  So self is able to be passed in because the
super object implicitly knows what self is.

Cheers,
Ian

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is this the proper way to use a class method? John Salerno <johnjsal@gmail.com> - 2012-03-01 22:00 -0800
  Re: Is this the proper way to use a class method? Chris Rebert <clp2@rebertia.com> - 2012-03-01 22:25 -0800
    Re: Is this the proper way to use a class method? John Salerno <johnjsal@gmail.com> - 2012-03-01 23:16 -0800
      Re: Is this the proper way to use a class method? Ian Kelly <ian.g.kelly@gmail.com> - 2012-03-02 01:04 -0700
      Re: Is this the proper way to use a class method? Chris Rebert <clp2@rebertia.com> - 2012-03-02 00:08 -0800
        Re: Is this the proper way to use a class method? John Salerno <johnjsal@gmail.com> - 2012-03-02 10:51 -0800
        Re: Is this the proper way to use a class method? John Salerno <johnjsal@gmail.com> - 2012-03-02 10:51 -0800
    Re: Is this the proper way to use a class method? John Salerno <johnjsal@gmail.com> - 2012-03-01 23:16 -0800

csiph-web