[Python-checkins] r75028 - in python/branches/py3k: Doc/library/functions.rst Lib/test/test_range.py Misc/NEWS Objects/rangeobject.c

Georg Brandl g.brandl at gmx.net
Wed Sep 23 15:14:10 CEST 2009


Mark Dickinson schrieb:
> On Wed, Sep 23, 2009 at 2:00 PM, Mark Dickinson <dickinsm at gmail.com> wrote:
>> On Wed, Sep 23, 2009 at 1:28 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>> mark.dickinson wrote:
>>>> +static int
>>>> +range_contains(rangeobject *r, PyObject *ob) {
>>>> +    if (PyLong_Check(ob)) {
>>>
>>> Could we be a little more generous here and use operator.index?
>>
>> But that would be a behaviour change;  is that desirable?  E.g.,
>> [...]
> 
> More to the point, would it be acceptable for
> 
> x in range(0, 10, 2)
> 
> and
> 
> x in list(range(0, 10, 2))
> 
> to return different results?

IMO, that should not be acceptable.  We cannot prevent __contains__
for user-defined types from doing something different from comparing to
the items that are yielded when the object is iterated over, but core
types should not introduce such confusing behavior.

Georg



More information about the Python-checkins mailing list