[issue19145] Inconsistent behaviour in itertools.repeat when using negative times
Larry Hastings
report at bugs.python.org
Wed Jan 22 21:36:02 CET 2014
Larry Hastings added the comment:
This problem been independently rediscovered by people converting
code to Argument Clinic. A Python signature can't express these
semantics, where a parameter behaves differently depending on
whether it's passed in by keyword or by reference. So Argument
Clinic can't either. I think it would be best if itertools.repeat
behaved like a pure Python function--that is, that it behaved
the same whether "times" was passed in by position or by keyword.
What's I find curious: the documentation is wildly out of sync with the implementation. It says:
itertools.repeat(object[, times])
....
def repeat(object, times=None):
....
http://docs.python.org/3.4/library/itertools.html#itertools.repeat
But repeat() doesn't support passing in None for the times parameter,
if indeed it ever has.
I see two possible choices here.
1) Honor the existing behavior. Change the signature to simply
def repeat(object, times=-1):
and document it that way.
2) Honor the documentation. Change the implementation to
def repeat(object, times=None):
This change could break code. So we'd have to go through a
deprecation cycle. Breaking "times=-1" without a deprecation
cycle is simply not viable at this point.
I could live with either.
----------
nosy: +larry
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19145>
_______________________________________
More information about the Python-bugs-list
mailing list