Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc for itertools, 'islice()' implementation have unwanted behavior for recipe 'consume()' #71399

Closed
alex0307 mannequin opened this issue Jun 4, 2016 · 11 comments
Closed
Assignees
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@alex0307
Copy link
Mannequin

alex0307 mannequin commented Jun 4, 2016

BPO 27212
Nosy @rhettinger, @Shredder13, @alex0307, @csabella
PRs
  • bpo-27212: Modify islice recipe to consume initial values preceding start #6195
  • [3.7] bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195) #6266
  • [3.6] bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195) #6267
  • [2.7] bpo-27212: Modify islice recipe to consume initial values prece… #6339
  • Files
  • islice_my.py: A simple fix of islice()
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/csabella'
    closed_at = <Date 2018-04-02.05:29:54.113>
    created_at = <Date 2016-06-04.05:33:46.942>
    labels = ['type-bug', 'docs']
    title = "Doc for itertools, 'islice()' implementation have unwanted behavior for recipe 'consume()'"
    updated_at = <Date 2018-04-02.17:36:40.481>
    user = 'https://github.com/alex0307'

    bugs.python.org fields:

    activity = <Date 2018-04-02.17:36:40.481>
    actor = 'cheryl.sabella'
    assignee = 'cheryl.sabella'
    closed = True
    closed_date = <Date 2018-04-02.05:29:54.113>
    closer = 'rhettinger'
    components = ['Documentation']
    creation = <Date 2016-06-04.05:33:46.942>
    creator = 'alex0307'
    dependencies = []
    files = ['43184']
    hgrepos = []
    issue_num = 27212
    keywords = ['patch']
    message_count = 11.0
    messages = ['267236', '275432', '314164', '314235', '314269', '314490', '314491', '314492', '314800', '314801', '314816']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'docs@python', 'Nofar Schnider', 'alex0307', 'cheryl.sabella']
    pr_nums = ['6195', '6266', '6267', '6339']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27212'
    versions = ['Python 2.7']

    @alex0307
    Copy link
    Mannequin Author

    alex0307 mannequin commented Jun 4, 2016

    In the doc for itertools, the python implementation of islice() doesn't actually perform the iteration when given an empty slice (e.g. islice(it,3,3)).

    This is not the expected behavior for 'consume()' in the recipe given below, i.e. consume(it,3) couldn't actually advance the iterator for 3 steps ahead. Instead, the iterator stays at its starting position.

    As a simple fix, in the implementation of islice(), the length of the slice object should be checked first. If it's zero, the iterator should be advanced (slice.start-1) times, and return (See islice_my.py)

    @alex0307 alex0307 mannequin assigned docspython Jun 4, 2016
    @alex0307 alex0307 mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Jun 4, 2016
    @rhettinger
    Copy link
    Contributor

    The recipe should be modified to consume the initial values. Something like this:

    start, stop, step = s.start or 0, s.stop or sys.maxsize, s.step or 1
    for i in zip(range(0, start), it):
        pass
    

    The recipe needs to pass these tests:

        it = iter('abcdefghi')
        assert list(islice(it, 4, 4)) == []
        assert list(it) == ['e', 'f', 'g', 'h', 'i']
        assert(list(islice('ABCDEFG', 2)) == ['A', 'B'])
        assert(list(islice('ABCDEFG', 2, 4)) == ['C', 'D'])
        assert(list(islice('ABCDEFG', 2, None)) == ['C', 'D', 'E', 'F', 'G'])
        assert(list(islice('ABCDEFG', 0, None, 2)) == ['A', 'C', 'E', 'G'])

    @rhettinger rhettinger assigned Shredder13 and unassigned rhettinger Sep 9, 2016
    @csabella
    Copy link
    Contributor

    Hi Nofar,

    Are you still interested in working on this issue? Thanks!

    @rhettinger
    Copy link
    Contributor

    Cheryl, I think you take this one. It hasn't been touched in a long time and Nofar is focused on another issue.

    @rhettinger rhettinger assigned csabella and unassigned Shredder13 Mar 22, 2018
    @csabella
    Copy link
    Contributor

    Thanks, Raymond. I'll take a look.

    @rhettinger
    Copy link
    Contributor

    New changeset da1734c by Raymond Hettinger (Cheryl Sabella) in branch 'master':
    bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195)
    da1734c

    @rhettinger
    Copy link
    Contributor

    New changeset f328caf by Raymond Hettinger (Miss Islington (bot)) in branch '3.7':
    bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195) (#GH-6266)
    f328caf

    @rhettinger
    Copy link
    Contributor

    New changeset c8698cf by Raymond Hettinger (Miss Islington (bot)) in branch '3.6':
    bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195) (GH-6267)
    c8698cf

    @rhettinger
    Copy link
    Contributor

    New changeset 325191b by Raymond Hettinger (Cheryl Sabella) in branch '2.7':
    [2.7] bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195) (GH-6339)
    325191b

    @rhettinger
    Copy link
    Contributor

    Thanks Cheryl. This was nice work :-)

    @csabella
    Copy link
    Contributor

    csabella commented Apr 2, 2018

    Thanks! :-)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants