[New-bugs-announce] [issue25926] problems with "times" keyword in itertools.repeat

Thomas Feldmann report at bugs.python.org
Tue Dec 22 12:40:36 EST 2015


New submission from Thomas Feldmann:

According to the docs `itertools.repeat(object[, times])` is equivalent to

```
def repeat(object, times=None):
    # repeat(10, 3) --> 10 10 10
    if times is None:
        while True:
            yield object
    else:
        for i in range(times):
            yield object
```

But it raises a TypeError when used this way:

```
Python 3.5.1 (default, Dec 10 2015, 10:34:07)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.1.76)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from itertools import repeat
>>> repeat('x', times=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer
```

The `times` keyword can be omitted but not explicitly set to None.
I checked with Python Versions 2.7 and 3.5.1 on Mac OS X and Windows 10.

----------
components: Interpreter Core
messages: 256847
nosy: Thomas Feldmann
priority: normal
severity: normal
status: open
title: problems with "times" keyword in itertools.repeat
type: behavior
versions: Python 2.7, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25926>
_______________________________________


More information about the New-bugs-announce mailing list