Re: specifying objects' class
Sebastien Bigaret <[email protected]> 10 Feb 2004 21:48:49 +0100
| Newsgroups | gmane.comp.python.modeling |
|---|---|
| Message-ID | <[email protected]> |
John Lenton <[email protected]> wrote: > On Tue, Feb 10, 2004 at 04:28:22PM +0100, Sebastien Bigaret wrote: > > [...] > > rather you want: > > > > Employee <|-- EmployeeBase <|-- Person <|-- PersonBase > > > > so that Employee inherits from the business-logic defined in Person, > > as expected. > > hmm... it isn't clear to me that this is always what you want; > currently we're using (in an unrelated field) a linearization of that > graph into > > Employee <| Person <| EmployeeBase <| PersonBase > > although I can see that in this case you are (on first sight at least) > correct. However, no matter what is expected, it is exactly what the > C3 MRO in python 2.3 does. If you want your behaviour, all you have to > do is declare Employee as > > class Employee(EmployeeBase, Person) > > whereas if you want the other behaviour you declare it as > > class Employee(Person, EmployeeBase) > > unfortunately this only applies to new style classes as of python 2.3; > I'm not certain the (hackish) MRO in 2.2 DWIMs. Fine, no problem! I only wanted to point out the fact that Employee should inherit from both EmployeeBase and Person (and additionally, the generated code works for py2.1, 2.2 and 2.3, so I used strict single-inheritance). > new-style classes would be nice for several reasons, not only > performance. For starters, the fact that you can query the MRO and use > super(), makes multiple inheritance manageable. > > By the way, did you compare the speed of your metaclass approach to an > exec? Sorry, I'm afraid I do not understand what "comparing to an exec" means, could you be more explicit? -- Sébastien. ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn