Skip to content

Rule to detect changes to iterable object of loop #445

@mimre25

Description

@mimre25

Recently I've ran into a classic bug in a code base, to illustrate a minimal example:

some_list = [1,2,3]
for i in some_list:
  if i % 2 == 0:
    some_list.remove(i)
  print(i)

To nobodies surprise this prints only 1 and 2.

I was surprised that none of my linters caught this.

Anyway, would it be possible to add a rule that detects changes to the iterable that is being iterated?

I'm also more than happy to contribute 🙂

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