[pypy-dev] funny observation with range
Samuele Pedroni
pedronis at strakt.com
Mon Sep 12 04:19:50 CEST 2005
Christian Tismer wrote:
> Hi Armin,
>
> when I added a few tests for the new variable step variant,
> I observed the following behavior of ranges:
>
> When a variable is conditionally assigned two different ranges,
> the ranges are kept, unless the steps are different.
> Well, after all this is not too surprizing, since we are compiling
> the step constant in.
> But I thing the action taken is not so pleasant:
> The range is turned into a list in this case!
>
> I guess what we want is either special-casing the respective blocks,
> or at least map this to the variable step case, if this is possible.
>
> I would like to understand why the annotator thinks this must
> become a list, and how I can convince it to take a different action.
> I think, using the variable variant would be adequate in this case.
you changed what happens on range calls annotation-wise, but not the
behavior of what should occur when types are mixed, this is specified by
the union operation which for list/ranges basically goes through the
ListItem.merge, which still has the behavior that mixing different-step
ranges unifies to list:
if other.range_step != self.range_step:
self.range_step = None
in listdef.py . If I have understood your changes you want 0 in this
case unless one of the range_step is already None meaning list.
Notice that if you change this you probably need to change
rtype_builtin_range because this assumes that it can use partially the
information in its arguments instead of about the result to decide
what to produce.
> A test_range_funny was added to test_rrange.py, not really
> meant as a test, but to explain that.
>
> Please let me know what you think.
>
> cheers - chris
>
More information about the pypy-dev
mailing list