|
1 | 1 | from collections import deque |
2 | 2 |
|
| 3 | +# Cas non conformes |
3 | 4 | numbers = [] |
4 | 5 | numbers.insert(0, val) # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
5 | 6 |
|
6 | 7 | items = [] |
7 | 8 | items.insert(0, "start") # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
8 | 9 |
|
9 | | -mylist = [] |
10 | | -mylist.insert(0.0, val) |
11 | | - |
12 | | -a = 0 |
13 | | -mylist.insert(a, val) |
14 | | - |
15 | | -dq = deque() |
16 | | -dq.appendleft("start") |
17 | | - |
18 | | -data = [] |
19 | | -data.insert(1, "something") |
20 | | - |
21 | 10 | lst = [] |
22 | 11 | (lst).insert(0, 'x') # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
23 | 12 |
|
|
27 | 16 | def insert_first(l, v): |
28 | 17 | l.insert(0, v) # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
29 | 18 |
|
30 | | -def add_to_front(dq, item): |
31 | | - dq.appendleft(item) |
32 | | - |
33 | 19 | some_list = [] |
34 | | -some_list.insert(index=0, object=val) # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
| 20 | +some_list.insert(index=0, object=val) # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
35 | 21 |
|
36 | 22 | deque_like = [] |
37 | 23 | deque_like.insert(0, "bad") # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
38 | 24 |
|
| 25 | +[1, 2, 3].insert(0, 9) # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
| 26 | + |
| 27 | +class MyList(list): |
| 28 | + pass |
| 29 | + |
| 30 | +custom_list = MyList() |
| 31 | +custom_list.insert(0, 'z') # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
| 32 | + |
| 33 | +def wrapper(): |
| 34 | + lst = [] |
| 35 | + lst.insert(0, "wrapped") # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
| 36 | + |
| 37 | + |
| 38 | +dq = deque() |
| 39 | +dq.appendleft("start") |
| 40 | + |
| 41 | +mylist = [] |
| 42 | +mylist.insert(0.0, val) # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
| 43 | + |
| 44 | + |
| 45 | +data = [] |
| 46 | +data.insert(1, "something") |
| 47 | + |
39 | 48 | real_deque = deque() |
40 | | -real_deque.appendleft("good") |
| 49 | +real_deque.appendleft("good") |
41 | 50 |
|
42 | | -fn = getattr(mylist, "insert") |
43 | | -fn(0, val) |
44 | 51 |
|
45 | | -[1, 2, 3].insert(0, 9) # Noncompliant {{Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list}} |
| 52 | +other_list = [] |
| 53 | +position = 1 |
| 54 | +other_list.insert(position, "ok") |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +val = "new" |
| 59 | +queue = deque() |
| 60 | +queue.appendleft(val) |
| 61 | + |
0 commit comments