Guido van Rossum
guido at python.org
Tue Feb 10 15:53:52 CET 2009
Seems to me jou are describing delegation.
On Tue, Feb 10, 2009 at 6:38 AM, spir <denis.spir at free.fr> wrote:
> Le Wed, 11 Feb 2009 00:42:50 +1100,
> Steven D'Aprano <steve at pearwood.info> a écrit :
>> > Moreover --this is the reason why I first had to study that point
>> > closer--, the present syntax requires the base type to be unique
>> > *and* known at design time.
>> I don't think so. Just write a class factory.
>> >>> def factory(base):
>> ... class MyThing(base):
>> ... def method(self):
>> ... return "self is a %s" % base.__name__
>> ... return MyThing
>> >>> x = factory(int)()
>> >>> x.method()
>> 'self is a int'
>> >>> y = factory(str)()
>> >>> y.method()
>> 'self is a str'
> I considered this approach already. It does not solve the problem at all. It's not the class's base type that is undefined at design time; it's the "base data"'s type. Each instance's base data may be of any type. In other words base==type(data) for each instance.
> Researches on the topic have revealed nothing except for a thread on SWIG's site. They were confronted to precisely the same issue, and seemed to have no more clue on a possible workaroud.
> la vida e estranya
> Python-ideas mailing list
> Python-ideas at python.org
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-ideas