|
| 1 | +--- |
| 2 | +source: crates/ruff_linter/src/rules/pylint/mod.rs |
| 3 | +--- |
| 4 | +modified_iterating_set.py:4:1: PLE4703 [*] Iterated set `nums` is modified within the `for` loop |
| 5 | + | |
| 6 | +3 | nums = {1, 2, 3} |
| 7 | +4 | / for num in nums: |
| 8 | +5 | | nums.add(num + 1) |
| 9 | + | |_____________________^ PLE4703 |
| 10 | +6 | |
| 11 | +7 | animals = {"dog", "cat", "cow"} |
| 12 | + | |
| 13 | + = help: Iterate over a copy of `nums` |
| 14 | + |
| 15 | +ℹ Unsafe fix |
| 16 | +1 1 | # Errors |
| 17 | +2 2 | |
| 18 | +3 3 | nums = {1, 2, 3} |
| 19 | +4 |-for num in nums: |
| 20 | + 4 |+for num in nums.copy(): |
| 21 | +5 5 | nums.add(num + 1) |
| 22 | +6 6 | |
| 23 | +7 7 | animals = {"dog", "cat", "cow"} |
| 24 | + |
| 25 | +modified_iterating_set.py:8:1: PLE4703 [*] Iterated set `animals` is modified within the `for` loop |
| 26 | + | |
| 27 | + 7 | animals = {"dog", "cat", "cow"} |
| 28 | + 8 | / for animal in animals: |
| 29 | + 9 | | animals.pop("cow") |
| 30 | + | |______________________^ PLE4703 |
| 31 | +10 | |
| 32 | +11 | fruits = {"apple", "orange", "grape"} |
| 33 | + | |
| 34 | + = help: Iterate over a copy of `animals` |
| 35 | + |
| 36 | +ℹ Unsafe fix |
| 37 | +5 5 | nums.add(num + 1) |
| 38 | +6 6 | |
| 39 | +7 7 | animals = {"dog", "cat", "cow"} |
| 40 | +8 |-for animal in animals: |
| 41 | + 8 |+for animal in animals.copy(): |
| 42 | +9 9 | animals.pop("cow") |
| 43 | +10 10 | |
| 44 | +11 11 | fruits = {"apple", "orange", "grape"} |
| 45 | + |
| 46 | +modified_iterating_set.py:12:1: PLE4703 [*] Iterated set `fruits` is modified within the `for` loop |
| 47 | + | |
| 48 | +11 | fruits = {"apple", "orange", "grape"} |
| 49 | +12 | / for fruit in fruits: |
| 50 | +13 | | fruits.clear() |
| 51 | + | |__________________^ PLE4703 |
| 52 | +14 | |
| 53 | +15 | planets = {"mercury", "venus", "earth"} |
| 54 | + | |
| 55 | + = help: Iterate over a copy of `fruits` |
| 56 | + |
| 57 | +ℹ Unsafe fix |
| 58 | +9 9 | animals.pop("cow") |
| 59 | +10 10 | |
| 60 | +11 11 | fruits = {"apple", "orange", "grape"} |
| 61 | +12 |-for fruit in fruits: |
| 62 | + 12 |+for fruit in fruits.copy(): |
| 63 | +13 13 | fruits.clear() |
| 64 | +14 14 | |
| 65 | +15 15 | planets = {"mercury", "venus", "earth"} |
| 66 | + |
| 67 | +modified_iterating_set.py:16:1: PLE4703 [*] Iterated set `planets` is modified within the `for` loop |
| 68 | + | |
| 69 | +15 | planets = {"mercury", "venus", "earth"} |
| 70 | +16 | / for planet in planets: |
| 71 | +17 | | planets.discard("mercury") |
| 72 | + | |______________________________^ PLE4703 |
| 73 | +18 | |
| 74 | +19 | colors = {"red", "green", "blue"} |
| 75 | + | |
| 76 | + = help: Iterate over a copy of `planets` |
| 77 | + |
| 78 | +ℹ Unsafe fix |
| 79 | +13 13 | fruits.clear() |
| 80 | +14 14 | |
| 81 | +15 15 | planets = {"mercury", "venus", "earth"} |
| 82 | +16 |-for planet in planets: |
| 83 | + 16 |+for planet in planets.copy(): |
| 84 | +17 17 | planets.discard("mercury") |
| 85 | +18 18 | |
| 86 | +19 19 | colors = {"red", "green", "blue"} |
| 87 | + |
| 88 | +modified_iterating_set.py:20:1: PLE4703 [*] Iterated set `colors` is modified within the `for` loop |
| 89 | + | |
| 90 | +19 | colors = {"red", "green", "blue"} |
| 91 | +20 | / for color in colors: |
| 92 | +21 | | colors.remove("red") |
| 93 | + | |________________________^ PLE4703 |
| 94 | +22 | |
| 95 | +23 | odds = {1, 3, 5} |
| 96 | + | |
| 97 | + = help: Iterate over a copy of `colors` |
| 98 | + |
| 99 | +ℹ Unsafe fix |
| 100 | +17 17 | planets.discard("mercury") |
| 101 | +18 18 | |
| 102 | +19 19 | colors = {"red", "green", "blue"} |
| 103 | +20 |-for color in colors: |
| 104 | + 20 |+for color in colors.copy(): |
| 105 | +21 21 | colors.remove("red") |
| 106 | +22 22 | |
| 107 | +23 23 | odds = {1, 3, 5} |
| 108 | + |
| 109 | +modified_iterating_set.py:24:1: PLE4703 [*] Iterated set `odds` is modified within the `for` loop |
| 110 | + | |
| 111 | +23 | odds = {1, 3, 5} |
| 112 | +24 | / for num in odds: |
| 113 | +25 | | if num > 1: |
| 114 | +26 | | odds.add(num + 1) |
| 115 | + | |_________________________^ PLE4703 |
| 116 | +27 | |
| 117 | +28 | # OK |
| 118 | + | |
| 119 | + = help: Iterate over a copy of `odds` |
| 120 | + |
| 121 | +ℹ Unsafe fix |
| 122 | +21 21 | colors.remove("red") |
| 123 | +22 22 | |
| 124 | +23 23 | odds = {1, 3, 5} |
| 125 | +24 |-for num in odds: |
| 126 | + 24 |+for num in odds.copy(): |
| 127 | +25 25 | if num > 1: |
| 128 | +26 26 | odds.add(num + 1) |
| 129 | +27 27 | |
0 commit comments