rspec/rules/S6417/python/rule.adoc

16 lines
507 B
Plaintext

== Why is this an issue?
Generally it is not recommended to modify a collection while it is being iterated over. This may lead to exceptions and it could be the source of incorrect or unspecified behaviors in the code.
This rule raises an issue when a method modifies the size of a collection, while the same collection is iterated.
=== Noncompliant code example
[source,python]
----
def my_fun(my_dict):
for key in my_dict:
if key == 'foo':
my_dict.pop(key) # Noncompliant
----