Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #84800
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: An object is an instance (or not)? |
| Date | 2015-01-29 19:22 +1300 |
| Message-ID | <ciu1taFjekrU1@mid.individual.net> (permalink) |
| References | (2 earlier) <MPG.2f3248ebaccae0069896a9@nntp.aioe.org> <mailman.18195.1422405040.18130.python-list@python.org> <MPG.2f324d0d46ba9afc9896ac@nntp.aioe.org> <cirs87F1tdrU2@mid.individual.net> <54c8cd8f$0$12975$c3e8da3$5496439d@news.astraweb.com> |
Steven D'Aprano wrote: > In fairness, "inherit" is standard terminology for the way instances get > their behaviour from their class. I'm not sure that's true, but even if it is, it's not the same kind of inheritance relationship as exists between a class and a base class, which was my point. > Also, you can override methods *on the instance*: I wouldn't call that a method -- it's just an instance attribute that happens to be a function. You can tell it's not a method because it doesn't get a 'self' argument. > In Python, obj.talk performs the following (grossly simplified) > process: > > * search the instance for an attribute "talk" > * search the class > * search all the base classes > * fail > > (simplified because I have ignored the roles of __getattr__ and > __getattribute__, of metaclasses, and the descriptor protocol) By ignoring the descriptor protocol, you're simplifying away something very important. It's the main thing that makes the instance-of relation different from the subclass-of relation. > The normal way of giving a class methods that are callable from the class is > to define them on the class with the classmethod or staticmethod > decorators. Using a metaclass is usually overkill :-) True, but I was trying to illustrate the symmetry between classes and instances, how the classic OOP ideas of Smalltalk et al are manifest in Python, and to show that classes *can* "participate fully in OOP" just like any other objects if you want them to. Python's "class methods" are strange beasts that don't have an equivalent in the classic OOP model, so they would only have confused matters. And there are cases where you *do* need a metaclass, such as giving a __dunder__ method to a class, so it's useful to know how to do it just in case. > An early essay on Python metaclasses was subtitled "The Killer-Joke". Quick, translate this post into German before anyone sees too much of it! -- Greg
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-27 21:12 +0100
Re: An object is an instance (or not)? Ethan Furman <ethan@stoneleaf.us> - 2015-01-27 12:36 -0800
Re: An object is an instance (or not)? André Roberge <andre.roberge@gmail.com> - 2015-01-27 12:50 -0800
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-27 22:06 +0100
Re: An object is an instance (or not)? André Roberge <andre.roberge@gmail.com> - 2015-01-27 13:38 -0800
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-27 22:43 +0100
Re: An object is an instance (or not)? André Roberge <andre.roberge@gmail.com> - 2015-01-27 13:49 -0800
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-27 22:58 +0100
Re: An object is an instance (or not)? Ben Finney <ben+python@benfinney.id.au> - 2015-01-28 09:32 +1100
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 18:55 +1100
Re: An object is an instance (or not)? Ben Finney <ben+python@benfinney.id.au> - 2015-01-28 22:20 +1100
Re: An object is an instance (or not)? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-27 23:12 +0000
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 01:52 +0100
Re: An object is an instance (or not)? Marko Rauhamaa <marko@pacujo.net> - 2015-01-28 07:25 +0200
Re: An object is an instance (or not)? Rustom Mody <rustompmody@gmail.com> - 2015-01-27 21:53 -0800
Re: An object is an instance (or not)? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-28 05:57 +0000
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 11:48 +0100
Re: An object is an instance (or not)? random832@fastmail.us - 2015-01-28 00:37 -0500
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 19:45 +1100
Re: An object is an instance (or not)? Devin Jeanpierre <jeanpierreda@gmail.com> - 2015-01-27 21:43 -0800
Re: An object is an instance (or not)? random832@fastmail.us - 2015-01-28 01:01 -0500
Re: An object is an instance (or not)? Rustom Mody <rustompmody@gmail.com> - 2015-01-27 22:22 -0800
Re: An object is an instance (or not)? Ben Finney <ben+python@benfinney.id.au> - 2015-01-28 18:03 +1100
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 19:48 +1100
Re: An object is an instance (or not)? Ben Finney <ben+python@benfinney.id.au> - 2015-01-28 17:59 +1100
Re: An object is an instance (or not)? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-01-28 20:21 +1300
Re: An object is an instance (or not)? Ben Finney <ben+python@benfinney.id.au> - 2015-01-28 18:48 +1100
Re: An object is an instance (or not)? random832@fastmail.us - 2015-01-28 12:08 -0500
Re: An object is an instance (or not)? Rustom Mody <rustompmody@gmail.com> - 2015-01-28 18:29 -0800
Re: An object is an instance (or not)? Ned Batchelder <ned@nedbatchelder.com> - 2015-01-27 18:22 -0500
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 01:17 +0100
Re: An object is an instance (or not)? Chris Angelico <rosuav@gmail.com> - 2015-01-28 11:30 +1100
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 01:35 +0100
Re: An object is an instance (or not)? alex23 <wuwei23@gmail.com> - 2015-01-28 14:44 +1000
Re: An object is an instance (or not)? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-01-28 23:33 +1300
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 22:52 +1100
Re: An object is an instance (or not)? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-01-29 19:22 +1300
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-29 18:16 +1100
Re: An object is an instance (or not)? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-29 08:48 -0700
Re: An object is an instance (or not)? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-01-30 22:07 +1300
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-31 10:45 +1100
Re: An object is an instance (or not)? Ned Batchelder <ned@nedbatchelder.com> - 2015-01-27 21:21 -0500
Re: An object is an instance (or not)? Rustom Mody <rustompmody@gmail.com> - 2015-01-27 18:52 -0800
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 20:16 +1100
Re: An object is an instance (or not)? Chris Angelico <rosuav@gmail.com> - 2015-01-28 21:01 +1100
Re: An object is an instance (or not)? Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-29 14:22 -0800
Re: An object is an instance (or not)? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-27 19:15 -0700
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 20:28 +1100
Re: An object is an instance (or not)? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-01-28 23:33 +1300
Re: An object is an instance (or not)? Grant Edwards <invalid@invalid.invalid> - 2015-01-28 00:23 +0000
Re: An object is an instance (or not)? Ben Finney <ben+python@benfinney.id.au> - 2015-01-28 10:39 +1100
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 01:24 +0100
Re: An object is an instance (or not)? Ben Finney <ben+python@benfinney.id.au> - 2015-01-28 12:00 +1100
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 02:14 +0100
Re: An object is an instance (or not)? alex23 <wuwei23@gmail.com> - 2015-01-28 14:47 +1000
Re: An object is an instance (or not)? Rustom Mody <rustompmody@gmail.com> - 2015-01-27 21:23 -0800
Re: An object is an instance (or not)? random832@fastmail.us - 2015-01-28 00:44 -0500
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 20:21 +1100
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 20:17 +1100
Re: An object is an instance (or not)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 20:09 +1100
Re: An object is an instance (or not)? Chris Angelico <rosuav@gmail.com> - 2015-01-28 10:42 +1100
Re: An object is an instance (or not)? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 01:31 +0100
Re: An object is an instance (or not)? Rustom Mody <rustompmody@gmail.com> - 2015-01-27 18:11 -0800
csiph-web