Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21130
| 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 | 2012-03-02 01:04 -0700 |
| Subject | Re: Is this the proper way to use a class method? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.344.1330675495.3037.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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