Next step after pychecker

Steve Holden steve at holdenweb.com
Wed Feb 2 07:36:29 EST 2005


Skip Montanaro wrote:

>     Francis> "Every well-formed expression of the language can be assigned a
>     Francis> type that can be deduced from the constituents of the
>     Francis> expression alone." Bird and Wadler, Introduction to Functional
>     Francis> Programming, 1988
> 
>     Francis> This is certainly not the case for Python since one and the
>     Francis> same variable can have different types depending upon the
>     Francis> execution context. Example :
> 
>     Francis> 1- if a is None:
>     Francis> 2-   b = 1
>     Francis> 3- else:
>     Francis> 4-   b = "Phew"
>     Francis> 5- b = b + 1
> 
>     Francis> One cannot statically determine the type of b by examining the
>     Francis> line 5- alone.
> 
> Do you have an example using a correct code fragment?  It makes no sense to
> infer types in code that would clearly raise runtime errors:
> 
>     >>> "Phew" + 1
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in ?
>     TypeError: cannot concatenate 'str' and 'int' objects
> 
> Also, note that the type assigned to an expression may be nothing more than
> "object".  Clearly that wouldn't be very helpful when trying to write an
> optimizing compiler, but it is a valid type.
> 
> Skip

So reaplce the plus sign with an asterisk ...

regards
  Steve
-- 
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005          http://www.python.org/pycon/2005/
Steve Holden                           http://www.holdenweb.com/



More information about the Python-list mailing list