[pypy-dev] [pypy-commit] pypy default: be a little more stringent about checking negative numbers early

Carl Friedrich Bolz cfbolz at gmx.de
Wed Oct 9 18:46:49 CEST 2013


Hi Maciej,

can you please write some tests for this change?

Cheers,

Carl Friedrich

On 09/10/13 09:57, fijal wrote:
> Author: Maciej Fijalkowski <fijall at gmail.com>
> Branch: 
> Changeset: r67229:c214edb11c30
> Date: 2013-10-09 09:55 +0200
> http://bitbucket.org/pypy/pypy/changeset/c214edb11c30/
> 
> Log:	be a little more stringent about checking negative numbers early
> 
> diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
> --- a/rpython/annotator/unaryop.py
> +++ b/rpython/annotator/unaryop.py
> @@ -333,12 +333,13 @@
>          check_negative_slice(s_start, s_stop)
>          lst.listdef.resize()
>  
> -def check_negative_slice(s_start, s_stop):
> +def check_negative_slice(s_start, s_stop, error="slicing"):
>      if isinstance(s_start, SomeInteger) and not s_start.nonneg:
> -        raise AnnotatorError("slicing: not proven to have non-negative start")
> +        raise AnnotatorError("%s: not proven to have non-negative start" %
> +                             error)
>      if isinstance(s_stop, SomeInteger) and not s_stop.nonneg and \
>             getattr(s_stop, 'const', 0) != -1:
> -        raise AnnotatorError("slicing: not proven to have non-negative stop")
> +        raise AnnotatorError("%s: not proven to have non-negative stop" % error)
>  
>  
>  class __extend__(SomeDict):
> @@ -448,12 +449,15 @@
>          return s_Bool
>  
>      def method_find(str, frag, start=None, end=None):
> +        check_negative_slice(start, end, "find")
>          return SomeInteger()
>  
>      def method_rfind(str, frag, start=None, end=None):
> +        check_negative_slice(start, end, "rfind")
>          return SomeInteger()
>  
>      def method_count(str, frag, start=None, end=None):
> +        check_negative_slice(start, end, "count")
>          return SomeInteger(nonneg=True)
>  
>      def method_strip(str, chr):
> _______________________________________________
> pypy-commit mailing list
> pypy-commit at python.org
> https://mail.python.org/mailman/listinfo/pypy-commit
> 



More information about the pypy-dev mailing list