Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PutBack behavior #313

@casey

Description

@casey

Thank you for itertools!

It's my fault for not reading the documentation for put_back, but I accidentally wrote a bug by putting two items back into an iterator and overwriting the old one.

I might be wrong, but this behavior seems a bit error prone, and might be unexpected.

I would consider renaming PutBack to PutBackOne, and PutBackN to PutBack. Unless the overwriting behavior is desirable, PutBack is essentially a speed/memory optimization when compared to PutBackN, so I would guide users to what is currently PutBackN, and they can then switch to what is currently PutBack as an optimization.

If the overwriting behavior is never desirable, it might be good to make it panic on the second call to put_back in a row. In my case, this would have saved me a bit of debugging time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions