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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4