Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2011-05-18 Thread John Nagle
On 5/4/2011 11:36 AM, Ethan Furman wrote: Raymond Hettinger wrote: I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. Multiple inheritance in Python is so badly designed that it probably should n

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2011-05-04 Thread Ethan Furman
Raymond Hettinger wrote: I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. Don't know if you are still looking for examples, but I recently came across a thread in Python-Dev which had an example u

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-12-12 Thread Daniel Urban
> So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. One other possibility is subclasses of the JSONEncoder class. For exam

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-30 Thread Sol Toure
Most of the examples presented here can use the "decorator pattern" instead. Especially the window system On Mon, Nov 29, 2010 at 5:27 PM, Gregory Ewing wrote: > Paul Rubin wrote: > > The classic example though is a window system, where you have a "window" >> class, and a "scroll bar" class, an

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-29 Thread Gregory Ewing
Paul Rubin wrote: The classic example though is a window system, where you have a "window" class, and a "scroll bar" class, and a "drop-down menu" class, etc. and if you want a window with a scroll bar and a drop-down menu, you inherit from all three of those classes. Not in any GUI library I'

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-29 Thread Giampaolo Rodolà
2010/11/24 Raymond Hettinger : > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant to most Python p

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-29 Thread Kirill Simonov
Hi Raymond, Another example: extensions in Mercurial. Mercurial is a VCS with a typical command line syntax: $ hg Mercurial has an extension mechanism for adding new and modifying existing commands. A big chunk of Mercurial functionality is implemented in `ui` and `repo` classes and ext

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-29 Thread Michele Simionato
On Nov 28, 2:01 pm, m...@distorted.org.uk (Mark Wooding) wrote: > Steve Holden writes: > > It isn't. Even inheritance itself isn't as useful as it at first > > appears, and composition turns out in practice to be much more useful. > > That goes double for multiple inheritance. > > Composition /wit

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread Raymond Hettinger
On Nov 28, 4:36 am, coldpizza wrote: > Did you try google code search? It is *not* the same as google code > hosting. > The site ishttp://www.google.com/codesearchand you can select Python > in the 'language' dropdown. Yes, I use Google's code search frequently and did try it for super(). However

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread André Malo
* Steve Holden wrote: > Even inheritance itself isn't as useful as it at first > appears, and composition turns out in practice to be much more useful. > That goes double for multiple inheritance. Amen. nd -- my @japh = (sub{q~Just~},sub{q~Another~},sub{q~Perl~},sub{q~Hacker~}); my $japh = q[su

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread Kirill Simonov
Hi Raymond, We've been using cooperative inheritance to implement stacked utilities such as WSGI middleware or connecting to a database. An example of a WSGI middleware stack: # Declare the interface and provide the default implementation. class WSGI(Utility): def __call__(self, environ,

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread Mark Wooding
Steve Holden writes: > It isn't. Even inheritance itself isn't as useful as it at first > appears, and composition turns out in practice to be much more useful. > That goes double for multiple inheritance. Composition /with a convenient notation for delegation/ works fairly well. Indeed, this c

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread coldpizza
On Nov 24, 11:08 pm, Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't seem to be relevant

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-27 Thread Steve Holden
On 11/27/2010 4:34 PM, Steven D'Aprano wrote: [...] > The problem isn't writing documentation for the feature, but coming up > with real-world use-cases. The documentation for super and the MRO is > extensive and detailed. It's also complicated, because multiple > inheritance is complicated. But

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-27 Thread Steven D'Aprano
On Fri, 26 Nov 2010 23:24:30 -0800, John Nagle wrote: > On 11/26/2010 4:21 PM, Mark Wooding wrote: [...] >>> @This catches the case where two classed both inherit from, say >>> "threading.thread", each expecting to have a private thread. >> >> Why on earth would anyone do such a bizarre thing? If

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-27 Thread Mark Wooding
John Nagle writes: > On 11/26/2010 4:21 PM, Mark Wooding wrote: > > John Nagle writes: > >> @This catches the case where two classed both inherit from, say > >> "threading.thread", each expecting to have a private thread. > > > > Why on earth would anyone do such a bizarre thing? If you want a

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-26 Thread John Nagle
On 11/26/2010 4:21 PM, Mark Wooding wrote: John Nagle writes: I'd argue that a better implementation would require that when there's a name clash, you have to specify the class containing the name. In other words, if A is a subclass of B, then B.foo() overrides A.foo(). But if C is a subclass

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-26 Thread Mark Wooding
John Nagle writes: > I'd argue that a better implementation would require that when there's > a name clash, you have to specify the class containing the name. In > other words, if A is a subclass of B, then B.foo() overrides > A.foo(). But if C is a subclass of A and B, and there's an A.foo() an

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-26 Thread John Nagle
On 11/25/2010 5:36 PM, Raymond Hettinger wrote: On Nov 25, 3:38 pm, John Nagle wrote: Best practice for this is "don't do it." Some name clashes ought to simply be detected as errors, rather than being given such complex semantics. That may well be true. If a coder has enough control

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-26 Thread Michele Simionato
On Nov 24, 9:08 pm, Raymond Hettinger wrote: > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. I do not know of other

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
[Paul Rubin] > I'd mention the SocketServer library, except I'm not sure what you > mean by "cooperative", so I don't know if that counts. Cooperative multiple inheritance is a specific problem when there is a diamond diagram with the same method name needing to be called on multiple paths and eac

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
On Nov 25, 3:38 pm, John Nagle wrote: >     Multiple inheritance in Python is basically what fell out of > CPython's internals, not a design.   Sorry to disagree. That is historically inaccurate. Guido designed super() on purpose. He took his cues from "Putting Metaclasses to Work" by Ira Forma

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Steven D'Aprano
On Thu, 25 Nov 2010 15:38:36 -0800, John Nagle wrote: > Part of the problem is the notion that if a base class is duplicated in > the hierarchy, there's only one copy. Why is that a problem? I would expect it to be a problem if it showed up twice. > So if you inherit from two > classes, both o

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Mark Wooding
John Nagle writes: >Multiple inheritance in Python is basically what fell out of > CPython's internals, not a design. It's one of those areas where > order of execution matters, and that wasn't well worked out. I'm not sure about the history, but this doesn't sound right to me. > Allowing

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread John Nagle
On 11/24/2010 12:08 PM, Raymond Hettinger wrote: I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. Google searches take me to old papers for C++ and Eiffel, but that don't seem to be relevant to most

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Paul Rubin
Raymond Hettinger writes: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. I'd mention the SocketServer library, except I'm not sure what you mean by "cooperative", so I don't know if that coun

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Aahz
In article <89b6d53f-dcdc-4442-957f-1f4d29115...@n32g2000pre.googlegroups.com>, Raymond Hettinger wrote: > >I'm writing-up more guidance on how to use super() and would like to >point at some real-world Python examples of cooperative multiple >inheritance. My previous job used this rather heavil

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Steve Holden
On 11/25/2010 4:40 PM, Raymond Hettinger wrote: > It's hard to write a best practices document for super() when > the doesn't appear to be any practice at all :-) > Sounds like the Python community have voted with their feet. I seem to remember that Alex Martelli's "Python in a Nutshell" contains

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
On Nov 24, 9:16 pm, Alice Bevan–McGregor wrote: > On 2010-11-24 12:08:04 -0800, Raymond Hettinger said: > > > I'm writing-up more guidance on how to use super() and would like to > > point at some real-world Python examples of cooperative multiple > > inheritance. > > The SocketServer module > (ht

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-24 Thread Alice Bevan–McGregor
On 2010-11-24 12:08:04 -0800, Raymond Hettinger said: I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. The SocketServer module (http://docs.python.org/library/socketserver.html) uses cooperative

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-24 Thread Antoine Pitrou
On Wed, 24 Nov 2010 12:08:04 -0800 (PST) Raymond Hettinger wrote: > I'm writing-up more guidance on how to use super() and would like to > point at some real-world Python examples of cooperative multiple > inheritance. > > Google searches take me to old papers for C++ and Eiffel, but that > don't

Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-24 Thread Raymond Hettinger
I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. Google searches take me to old papers for C++ and Eiffel, but that don't seem to be relevant to most Python programmers (i.e. a WalkingMenu example whe