Adaptation and typecasting (was Re: [Python-Dev] replacing 'global')

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Oct 28 18:03:34 EST 2003


> From: Phillip J. Eby [mailto:pje at telecommunity.com]

> 
> At 09:56 AM 10/28/03 +0100, Alex Martelli wrote:
> >AND, adaptation is not typecasting:
> >e.g y=adapt("23", int) should NOT succeed.
> 
> And, why do you consider adaptation *not* to be typecasting?  
> I always 
> think of it as "give me X, rendered as a Y", which certainly 
> sounds like a 
> description of typecasting to me.

Because (IMO anyway) adaption is *not* "give me X, rendered as Y". Adaption is "here is an X, can it be used as a Y?".

They are two distinct concepts, although obviously there are crossover points. A string cannot be used as an int, although an int can be created from the string representation of an int.

Adaption should not involve any change to the underlying data - mutating operations on the adapted object should (attempt to) mutate the original object (assuming the adapted object and original object are not one and the same).

Tim Delaney



More information about the Python-Dev mailing list