Re: [Modeling-users] specifying objects' class
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2004-02-10 20:47:28
|
John Lenton <jo...@vi...> wrote: > On Tue, Feb 10, 2004 at 04:28:22PM +0100, Sebastien Bigaret wrote: > > [...] > > rather you want: > >=20 > > Employee <|-- EmployeeBase <|-- Person <|-- PersonBase > >=20 > > so that Employee inherits from the business-logic defined in Person, > > as expected. >=20 > 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 >=20 > Employee <| Person <| EmployeeBase <| PersonBase >=20 > 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 >=20 > class Employee(EmployeeBase, Person) >=20 > whereas if you want the other behaviour you declare it as >=20 > class Employee(Person, EmployeeBase) >=20 > 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. >=20 > 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=E9bastien. |