Skip to content

Issue in iterator example code #1

Description

@yungnickyoung

From reddit:
"hey in the iterator part, the iter function resets self.n and returns self. so, i didnt test it, but if i am not mistaken, this means if you get an iterator and iterate it a few times, then getting another iterator from the same object should reset self.n for the first iterator as well. this can lead to self.n exceeding the desired max. iteration for the first iterator since it gets reset at some point when the second iterator is created."

See both of the answers here

Mention all solutions:

  • extraction of iterator to separate class
  • return built-in iterator on relevant object data, if applicable
  • make __iter__ a generator function

This should probably also be added to Common Gotchas 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions