[pypy-dev] unicode merge / exception catching

holger krekel hpk at trillke.net
Mon May 23 14:02:21 CEST 2005


Hi Arre, 

your merge looks pretty good so far.  
One issue relating to exceptions though. 

> Author: ac
> Date: Mon May 23 13:05:59 2005
> New Revision: 12735
> ... 
> ...
> --- pypy/dist/pypy/objspace/std/inttype.py	(original)
> +++ pypy/dist/pypy/objspace/std/inttype.py	Mon May 23 13:05:59 2005
> @@ -28,6 +28,15 @@
>                                       space.wrap(e.msg))
>              except ParseStringOverflowError, e:
>                   w_longval = retry_to_w_long(space, e.parser)                
> +        elif space.is_true(space.isinstance(w_value, space.w_unicode)):
> +            try:
> +                from unicodeobject import unicode_to_decimal_w
> +                value = string_to_int(space, unicode_to_decimal_w(space, w_value))
> +            except ParseStringError, e:
> +                raise OperationError(space.w_ValueError,
> +                                     space.wrap(e.msg))
> +            except ParseStringOverflowError, e:
> +                 w_longval = retry_to_w_long(space, e.parser)                

generally we should try to use "exact" exception catching 
both for readability and (i think, someone correct me) for easier 
translatability.   This means that you should only try-except
guard the exact call that can raise the exception. 

> +from pypy.objspace.std.fake import wrap_exception

and the usage: 

> -def float__Unicode(space, w_uni):
> -    try:
> -        return space.wrap(float(unicode_to_decimal_w(space, w_uni)))
> -    except:
> -        wrap_exception(space)

falls into the same "don't be so lazy and make the life possibly harder
for translation or the reader" category :-) 

cheers, 

    holger



More information about the Pypy-dev mailing list