[Python-Dev] PEP 246: let's reset
Nick Coghlan
ncoghlan at iinet.net.au
Mon Jan 17 12:49:42 CET 2005
Guido van Rossum wrote:
> Typechecking can be trivially defined in terms of adaptation:
>
> def typecheck(x, T):
> y = adapt(x, T)
> if y is x:
> return y
> raise TypeError("...")
Assuming the type error displayed contains information on T, the caller can then
trivially correct the type error by invoking adapt(arg, T) at the call point
(assuming the argument actually *is* adaptable to the desired protocol). The
code inside the function still gets to assume the supplied object has the
correct type - the only difference is that if adaptation is actually needed, the
onus is on the caller to provide it explicitly (and they will get a specific
error telling them so).
This strikes me as quite an elegant solution.
Regards,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-Dev
mailing list