Issue 25926: Clarify that the itertools pure python equivalents are only approximate. (original) (raw)

Created on 2015-12-22 17:40 by tfeldmann, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (10)

msg256847 - (view)

Author: Thomas Feldmann (tfeldmann)

Date: 2015-12-22 17:40

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.

msg256848 - (view)

Author: R. David Murray (r.david.murray) * (Python committer)

Date: 2015-12-22 17:46

Huh. I always thought the wording was "roughly equivalent to". This is a consequence of C vs python, and is the reason the docstring uses the [] notation.

msg265835 - (view)

Author: Camilla Montonen (Winterflower)

Date: 2016-05-18 20:11

Should 'roughly equivalent to' be added as a note to the docs?

msg265840 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2016-05-19 01:17

I'm okay with changing the docs to "roughly equivalent to". That will help prevent the occasional misreading as "precisely equivalent in every respect".

msg266478 - (view)

Author: Nofar Schnider (Nofar Schnider) * (Python triager)

Date: 2016-05-27 06:00

Issue #25926 Changed all "equivalent to" occurrences to "roughly equivalent to"

msg266480 - (view)

Author: Nofar Schnider (Nofar Schnider) * (Python triager)

Date: 2016-05-27 06:11

Attached a diff All occurrences of "equivalent to" are switched to "roughly equivalent to"

msg266542 - (view)

Author: Roundup Robot (python-dev) (Python triager)

Date: 2016-05-28 07:18

New changeset 613314c3f9ed by Raymond Hettinger in branch '3.5': Issue 25926: Clarify that the pure python equivalents are only approximate. https://hg.python.org/cpython/rev/613314c3f9ed

New changeset e67e970de54a by Raymond Hettinger in branch 'default': Issue 25926: Clarify that the pure python equivalents are only approximate. https://hg.python.org/cpython/rev/e67e970de54a

msg266543 - (view)

Author: Roundup Robot (python-dev) (Python triager)

Date: 2016-05-28 07:26

New changeset f66c30f66235 by Raymond Hettinger in branch '2.7': Issue 25926: Clarify that the pure python equivalents are only approximate. https://hg.python.org/cpython/rev/f66c30f66235

msg266544 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2016-05-28 07:27

Nofar, thanks for the patch.

msg266547 - (view)

Author: Roundup Robot (python-dev) (Python triager)

Date: 2016-05-28 11:26

New changeset 35fa2ec1f237 by Serhiy Storchaka in branch 'default': Merge heads (issue #25926). https://hg.python.org/cpython/rev/35fa2ec1f237

History

Date

User

Action

Args

2022-04-11 14:58:25

admin

set

github: 70114

2016-05-28 11:26:07

python-dev

set

messages: +

2016-05-28 07:27:44

rhettinger

set

status: open -> closed
title: problems with "times" keyword in itertools.repeat -> Clarify that the itertools pure python equivalents are only approximate.
messages: +

components: + Documentation, - Interpreter Core
resolution: fixed

2016-05-28 07:26:51

python-dev

set

messages: +

2016-05-28 07🔞42

python-dev

set

nosy: + python-dev
messages: +

2016-05-27 06:11:02

Nofar Schnider

set

files: + issue25926.diff
hgrepos: + hgrepo345
messages: +

keywords: + patch

2016-05-27 06:07:06

Nofar Schnider

set

files: - itertools.rst

2016-05-27 06:00:45

Nofar Schnider

set

files: + itertools.rst

nosy: + Nofar Schnider
messages: +

hgrepos: + hgrepo344

2016-05-19 01:17:50

rhettinger

set

priority: normal -> low

messages: +

2016-05-18 20:17:00

serhiy.storchaka

set

assignee: rhettinger

2016-05-18 20:11:31

Winterflower

set

nosy: + Winterflower
messages: +

2015-12-22 17:46:32

r.david.murray

set

nosy: + rhettinger, r.david.murray
messages: +

2015-12-22 17:40:36

tfeldmann

create