PEP 3107 and stronger typing (note: probably a newbie question)

paul paul at subsignal.org
Tue Jun 26 11:22:20 EDT 2007


Bruno Desthuilliers schrieb:
> Stephen R Laniel a écrit :
>> On Wed, Jun 20, 2007 at 09:41:09PM +0100, Michael Hoffman wrote:
>>> If you asked Java programmers why you couldn't turn *off* Java's static 
>>> type checking if you wanted to, you'd probably get a similar response.
>> Perhaps it would help for me to explain what I'd like.
>>
>> Under both Perl and Python, I've found myself
>> having/wanting to write things like so:
>>
>> def my_func( int_arg, str_arg ):
>>     try:
>>         int_arg = int( int_arg )
>>         str_arg = str( str_arg )
>>     except ValueError:
>>         sys.stderr.write( "Args are not of the right type\n" )
>>         sys.exit(1)
>>
> 
> Just a question : what will happen if you get rid of the try/except 
> block ?-)
> 
The error will remain unnoticed and the argument might survive another 
few function calls but eventually fails deep down somewhere with:

TypeError: cannot concatenate 'str' and 'list' objects

then you have to examine the traceback and hope the real error is 
visible somewhere (an argument not conforming to the specification of 
the function prototype, or the lack thereof).

cheers
  Paul




More information about the Python-list mailing list