HOWTO restrict multiply inherited class to on sub-class

Luke Kenneth Casson Leighton lkcl at angua.rince.de
Mon Apr 2 09:38:49 EDT 2001


please reply direct and to list, will check via web interface
as email is stuffed right now.

okay. c++ time.

class Base
{
};

okay, i've forgotten my c++.  c++ pseudo-code time :)

class Base1
{
};

class Inherited: public Base1, public Base
{
};

x = new Inherited();

y = (Base1*)x;
    ^^^^^^^

how do you do _this_ in python?

i.e. i have a Database-access class that inherits from about
six separate sub-database classes.

i want another class to have access to only ONE of the subsets
of functionality.

but there's no way i am going to create redirector functions,
one for each and every function i continue to add to the database
sub-classes.

*grumble* i suppose i could do this automatically *grumble*.
search for all functions in one sub-class and exec some code
that redirects *grumble*.

that's a lot of work, relative to a simple type-cast down to
a sub-class!

y = Base1.x?

class Base:
	def __init__(self):
		blah

class Base1:
	..

class Inherited(Base, Base1)

x = Inherited()

y = x.Base1  ???
y = x.getattr(Base1)  ???

y = Base1(x)   ???

any one of these is a candidate for possible typecast-equivalence,
compared to c++, neh?

yes, _i know_: writing this took longer than it would to actually
do the for-generate-function-redirects-exec *grumble* but this
bothers me :)

any clues, anyone?

if this doesn't exist, if there's no work-around - _reasonable_
workaround, perhaps i'll write a PEP.

luke (currently without an email home :)




More information about the Python-list mailing list