---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
PLE4703 [*] Iterated set `nums` is modified within the `for` loop
 --> modified_iterating_set.py:4:1
  |
3 |   nums = {1, 2, 3}
4 | / for num in nums:
5 | |     nums.add(num + 1)
  | |_____________________^
6 |
7 |   animals = {"dog", "cat", "cow"}
  |
help: Iterate over a copy of `nums`
  |
3 | nums = {1, 2, 3}
  - for num in nums:
4 + for num in nums.copy():
5 |     nums.add(num + 1)
  |
note: This is an unsafe fix and may change runtime behavior

PLE4703 [*] Iterated set `animals` is modified within the `for` loop
  --> modified_iterating_set.py:8:1
   |
 7 |   animals = {"dog", "cat", "cow"}
 8 | / for animal in animals:
 9 | |     animals.pop("cow")
   | |______________________^
10 |
11 |   fruits = {"apple", "orange", "grape"}
   |
help: Iterate over a copy of `animals`
  |
7 | animals = {"dog", "cat", "cow"}
  - for animal in animals:
8 + for animal in animals.copy():
9 |     animals.pop("cow")
  |
note: This is an unsafe fix and may change runtime behavior

PLE4703 [*] Iterated set `fruits` is modified within the `for` loop
  --> modified_iterating_set.py:12:1
   |
11 |   fruits = {"apple", "orange", "grape"}
12 | / for fruit in fruits:
13 | |     fruits.clear()
   | |__________________^
14 |
15 |   planets = {"mercury", "venus", "earth"}
   |
help: Iterate over a copy of `fruits`
   |
11 | fruits = {"apple", "orange", "grape"}
   - for fruit in fruits:
12 + for fruit in fruits.copy():
13 |     fruits.clear()
   |
note: This is an unsafe fix and may change runtime behavior

PLE4703 [*] Iterated set `planets` is modified within the `for` loop
  --> modified_iterating_set.py:16:1
   |
15 |   planets = {"mercury", "venus", "earth"}
16 | / for planet in planets:
17 | |     planets.discard("mercury")
   | |______________________________^
18 |
19 |   colors = {"red", "green", "blue"}
   |
help: Iterate over a copy of `planets`
   |
15 | planets = {"mercury", "venus", "earth"}
   - for planet in planets:
16 + for planet in planets.copy():
17 |     planets.discard("mercury")
   |
note: This is an unsafe fix and may change runtime behavior

PLE4703 [*] Iterated set `colors` is modified within the `for` loop
  --> modified_iterating_set.py:20:1
   |
19 |   colors = {"red", "green", "blue"}
20 | / for color in colors:
21 | |     colors.remove("red")
   | |________________________^
22 |
23 |   odds = {1, 3, 5}
   |
help: Iterate over a copy of `colors`
   |
19 | colors = {"red", "green", "blue"}
   - for color in colors:
20 + for color in colors.copy():
21 |     colors.remove("red")
   |
note: This is an unsafe fix and may change runtime behavior

PLE4703 [*] Iterated set `odds` is modified within the `for` loop
  --> modified_iterating_set.py:24:1
   |
23 |   odds = {1, 3, 5}
24 | / for num in odds:
25 | |     if num > 1:
26 | |         odds.add(num + 1)
   | |_________________________^
27 |
28 |   # OK
   |
help: Iterate over a copy of `odds`
   |
23 | odds = {1, 3, 5}
   - for num in odds:
24 + for num in odds.copy():
25 |     if num > 1:
   |
note: This is an unsafe fix and may change runtime behavior
