[Python-Dev] AC Derby and accepting None for optional positional arguments

Guido van Rossum guido at python.org
Thu Jan 16 19:42:35 CET 2014


On Thu, Jan 16, 2014 at 1:42 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 1/16/2014 3:31 AM, Serhiy Storchaka wrote:
>>
>> 16.01.14 08:05, Guido van Rossum написав(ла):
>>>
>>> In this specific case it's clear to me that the special-casing of
>>> negative count is intentional -- presumably it emulates sequence
>>> repetition, where e.g. 'a'*-1 == ''.
>>
>>
>> In this specific case it's contrary to sequence repetition. Because
>> repeat('a', -1) repeats 'a' forever.
>
>
> 'Forever' only when the keyword is used and the value is -1.
> In 3.4b2
>
>>>> itertools.repeat('a', -1)
> repeat('a', 0)
>>>> itertools.repeat('a', times=-1)
> repeat('a')
>>>> itertools.repeat('a', times=-2)
> repeat('a', -2)
>
>
>> This is a point of Vajrasky's issue [1].
>
> The first line is correct in both behavior and representation.
> The second line behavior (and corresponding repr) are wrong.
> The third line repr is wrong but the behavior is like the first.
>
>> [1] http://bugs.python.org/issue19145

Eew. This is much more wacko than I thought. (Serves me right for
basically not caring about itertools :-(. ) It also mostly sounds like
unintended -- I can't imagine the intention was to treat the keyword
argument different than the positional argument, but I can easily
imagine getting the logic slightly wrong.

If I had complete freedom in redefining the spec I would treat
positional and keyword the same, interpret absent or None to mean
"forever" and explicit negative integers to mean the same as zero, and
make repr show a positional integer >= 0 if the repeat isn't None.

But I don't know if that's too much of a change.

@Antoine:
>> Passing in "None" here is inconvenient as it's an integer argument.
>
> Inconvenient for whom? The callee or the caller?

I meant for the callee -- it's slightly complex to code up right. But
IMO worth it.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list