Type Hinting vs Type Checking and Preconditions

Donn Cave donn at u.washington.edu
Wed Mar 8 02:11:54 CET 2006


In article <mailman.2860.1141769413.27775.python-list at python.org>,
 "Delaney, Timothy (Tim)" <tdelaney at avaya.com> wrote:

> bearophileHUGS at lycos.com wrote:
> 
> > You can look at this, its API looks very well thought out to me:
> > http://oakwinter.com/code/typecheck/
> > 
> >> Now, on the other hand, if we were to introduce a purely optional
> >> type hint to the function prototype, such as follows:
> >> def multiplyByTwo(value:int): return value * 2
> > 
> > I don't think Python will have something like this...
> 
> It's actually something that has been being considered for Python 3.0
> for a long time.
> 
> Search for `python optional static typing` for discussions - the first
> two links from Google are blog entries by Guido from a year ago (there's
> also a third one linked from PEP 3000).

But surely, never with the proposed semantics (quoted to
match [non]attribution), with automatic conversion of
"14" to 14  --

> >> The python interpreter could do the work of casting the incoming
> >> parameter to an int (if it is not already) before it is multipled,
> >> resulting in the desired result or a typecasting error otherwise.
> >> Furthermore, it could do it more efficiently than a developer having to
> >> put conditional code at the beginning of traditionally typecasting
> >> functions.

I know awk works a bit like that, maybe Perl? but it's
surely way out of place in Python.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list