So we only add deprecation warning to only times=-1 via keyword or for all negative numbers to times via keyword?">

(original) (raw)

On 01/27/2014 06:00 PM, Vajrasky Kok wrote:
On Mon, Jan 27, 2014 at 9:13 PM, Larry Hastings  wrote:  
  
I apologize for not making myself clear. But that's part of what I meant,  
yes: we should preserve the existing behavior of times=-1 when passed in by  
position or by keyword. However, we should \*also\* add a deprecation warning  
when passing times=-1 by keyword, suggesting that they use times=None  
instead. The idea is that we could eventually remove the PyTuple\_Size check  
and make times=-1 always behave like times=0\. In practice it'd be okay with  
me if we never did, or at least not until Python 4.




So we only add deprecation warning to only times=-1 via keyword or for
all negative numbers to times via keyword?

I mean, what about:





from itertools import repeat
list(repeat('a', times=-2))









I should have been even *more* precise! When I said "times=-1" I
really meant all negative numbers. (I was trying to abbreviate it
as -1, as my text was already too long and unwieldly.)



I propose the logic be equivalent to this, handwaving for clarity
boilerplate error handling (the real implementation would handle
PyArg_ParseParseTupleAndKeywords or PyLong_ToPy_ssize_t failing):

PyObject *element, times = Py_None;

Py_ssize_t cnt;

PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:repeat", kwargs,
&element, &times);

if times == Py_None

cnt = -1

else

cnt = PyLong_ToPy_ssize_t(times)

if cnt < 0

if "times" was passed by keyword

issue DeprecationWarning, "use repeat(o, times=None)
to repeat indefinitely"

else

cnt = 0


(For those of you who aren't familiar with the source: "cnt" is the
internal variable used to set the repeat count of the iterator. If
"cnt" is < 0, the iterator repeats forever.)



If in the future we actually removed the deprecated behavior, the
last "if" block would change simply to

if cnt < 0

cnt = 0






/arry