hc99 commited on
Commit
2343f0f
·
verified ·
1 Parent(s): 17cd033

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtin_extension.py +4 -0
  2. testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtin_extension.rc +2 -0
  3. testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtin_extension.txt +2 -0
  4. testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtins.py +3 -0
  5. testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtins.rc +5 -0
  6. testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtins.txt +4 -0
  7. testbed/pylint-dev__pylint/tests/functional/ext/broad_try_clause/broad_try_clause_extension.py +49 -0
  8. testbed/pylint-dev__pylint/tests/functional/ext/broad_try_clause/broad_try_clause_extension.rc +2 -0
  9. testbed/pylint-dev__pylint/tests/functional/ext/broad_try_clause/broad_try_clause_extension.txt +4 -0
  10. testbed/pylint-dev__pylint/tests/functional/ext/check_elif/check_elif.py +48 -0
  11. testbed/pylint-dev__pylint/tests/functional/ext/check_elif/check_elif.rc +2 -0
  12. testbed/pylint-dev__pylint/tests/functional/ext/check_elif/check_elif.txt +4 -0
  13. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_assignment_expr.py +159 -0
  14. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_assignment_expr.rc +6 -0
  15. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_assignment_expr.txt +18 -0
  16. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_augmented_assign.py +135 -0
  17. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_augmented_assign.rc +3 -0
  18. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_augmented_assign.txt +27 -0
  19. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_namedtuple_or_dataclass.py +79 -0
  20. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_namedtuple_or_dataclass.rc +2 -0
  21. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_namedtuple_or_dataclass.txt +5 -0
  22. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_tuple.py +31 -0
  23. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_tuple.rc +2 -0
  24. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_tuple.txt +7 -0
  25. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_default.py +6 -0
  26. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_default.rc +2 -0
  27. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_py_version_35.py +7 -0
  28. testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_py_version_35.rc +3 -0
  29. testbed/pylint-dev__pylint/tests/functional/ext/comparison_placement/misplaced_comparison_constant.py +50 -0
  30. testbed/pylint-dev__pylint/tests/functional/ext/comparison_placement/misplaced_comparison_constant.rc +2 -0
  31. testbed/pylint-dev__pylint/tests/functional/ext/comparison_placement/misplaced_comparison_constant.txt +6 -0
  32. testbed/pylint-dev__pylint/tests/functional/ext/confusing_elif/confusing_elif.py +143 -0
  33. testbed/pylint-dev__pylint/tests/functional/ext/confusing_elif/confusing_elif.rc +2 -0
  34. testbed/pylint-dev__pylint/tests/functional/ext/confusing_elif/confusing_elif.txt +3 -0
  35. testbed/pylint-dev__pylint/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py +36 -0
  36. testbed/pylint-dev__pylint/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.rc +2 -0
  37. testbed/pylint-dev__pylint/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.txt +2 -0
  38. testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams.py +108 -0
  39. testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams.rc +9 -0
  40. testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams.txt +22 -0
  41. testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams_py38.py +34 -0
  42. testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams_py38.rc +11 -0
  43. testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams_py38.txt +2 -0
  44. testbed/pylint-dev__pylint/tests/functional/ext/docparams/missing_param_doc.py +142 -0
  45. testbed/pylint-dev__pylint/tests/functional/ext/docparams/missing_param_doc.rc +8 -0
  46. testbed/pylint-dev__pylint/tests/functional/ext/docparams/missing_param_doc.txt +15 -0
  47. testbed/pylint-dev__pylint/tests/functional/ext/docparams/parameter/missing_param_doc.py +12 -0
  48. testbed/pylint-dev__pylint/tests/functional/ext/docparams/parameter/missing_param_doc.rc +7 -0
  49. testbed/pylint-dev__pylint/tests/functional/ext/docparams/parameter/missing_param_doc_required.py +51 -0
  50. testbed/pylint-dev__pylint/tests/functional/ext/docparams/parameter/missing_param_doc_required.rc +7 -0
testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtin_extension.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # pylint: disable=missing-docstring
2
+
3
+ TEST = map(str, (1, 2, 3)) # [bad-builtin]
4
+ TEST1 = filter(str, (1, 2, 3)) # [bad-builtin]
testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtin_extension.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.bad_builtin,
testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtin_extension.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ bad-builtin:3:7:3:26::Used builtin function 'map'. Using a list comprehension can be clearer.:UNDEFINED
2
+ bad-builtin:4:8:4:30::Used builtin function 'filter'. Using a list comprehension can be clearer.:UNDEFINED
testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtins.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # pylint: disable=missing-docstring
2
+ input("Yes or no ? (Y=1, n=0)") # [bad-builtin]
3
+ print(map(str, filter(1, [1, 2, 3]))) # [bad-builtin, bad-builtin, bad-builtin]
testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtins.rc ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ [MAIN]
2
+ load-plugins = pylint.extensions.bad_builtin
3
+
4
+ [pylint.DEPRECATED_BUILTINS]
5
+ bad-functions=map,input,filter,print
testbed/pylint-dev__pylint/tests/functional/ext/bad_builtin/bad_builtins.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ bad-builtin:2:0:2:31::Used builtin function 'input':UNDEFINED
2
+ bad-builtin:3:15:3:35::Used builtin function 'filter'. Using a list comprehension can be clearer.:UNDEFINED
3
+ bad-builtin:3:6:3:36::Used builtin function 'map'. Using a list comprehension can be clearer.:UNDEFINED
4
+ bad-builtin:3:0:3:37::Used builtin function 'print':UNDEFINED
testbed/pylint-dev__pylint/tests/functional/ext/broad_try_clause/broad_try_clause_extension.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pylint: disable=missing-docstring, invalid-name
2
+
3
+ MY_DICTIONARY = {"key_one": 1, "key_two": 2, "key_three": 3}
4
+
5
+ try: # [too-many-try-statements]
6
+ value = MY_DICTIONARY["key_one"]
7
+ value += 1
8
+ print("This one has an except clause only.")
9
+ except KeyError:
10
+ pass
11
+
12
+ try: # [too-many-try-statements]
13
+ value = MY_DICTIONARY["key_one"]
14
+ value += 1
15
+ print("This one has a finally clause only.")
16
+ finally:
17
+ pass
18
+
19
+ try: # [too-many-try-statements]
20
+ value = MY_DICTIONARY["key_one"]
21
+ value += 1
22
+ print("This one has an except clause...")
23
+ print("and also a finally clause!")
24
+ except KeyError:
25
+ pass
26
+ finally:
27
+ pass
28
+
29
+ try: # [too-many-try-statements]
30
+ if "key_one" in MY_DICTIONARY:
31
+ entered_if_body = True
32
+ print("This verifies that content inside of an if statement is counted too.")
33
+ else:
34
+ entered_if_body = False
35
+
36
+ while False:
37
+ print("This verifies that content inside of a while loop is counted too.")
38
+
39
+ for item in []:
40
+ print("This verifies that content inside of a for loop is counted too.")
41
+
42
+
43
+ except KeyError:
44
+ pass
45
+
46
+ try:
47
+ value = MY_DICTIONARY["key_one"]
48
+ except KeyError:
49
+ value = 0
testbed/pylint-dev__pylint/tests/functional/ext/broad_try_clause/broad_try_clause_extension.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.broad_try_clause,
testbed/pylint-dev__pylint/tests/functional/ext/broad_try_clause/broad_try_clause_extension.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ too-many-try-statements:5:0:10:8::try clause contains 3 statements, expected at most 1:UNDEFINED
2
+ too-many-try-statements:12:0:17:8::try clause contains 3 statements, expected at most 1:UNDEFINED
3
+ too-many-try-statements:19:0:25:8::try clause contains 4 statements, expected at most 1:UNDEFINED
4
+ too-many-try-statements:29:0:44:8::try clause contains 7 statements, expected at most 1:UNDEFINED
testbed/pylint-dev__pylint/tests/functional/ext/check_elif/check_elif.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pylint: disable=no-else-raise,unsupported-membership-test,using-constant-test, comparison-of-constants
2
+
3
+ """Checks use of "else if" triggers a refactor message"""
4
+ from typing import Union, Sequence, Any, Mapping
5
+
6
+
7
+ def my_function():
8
+ """docstring"""
9
+ myint = 2
10
+ if myint > 5:
11
+ pass
12
+ else:
13
+ if myint <= 5: # [else-if-used]
14
+ pass
15
+ else:
16
+ myint = 3
17
+ if myint > 2:
18
+ if myint > 3:
19
+ pass
20
+ elif myint == 3:
21
+ pass
22
+ elif myint < 3:
23
+ pass
24
+ else:
25
+ if myint: # [else-if-used]
26
+ pass
27
+ else:
28
+ if myint:
29
+ pass
30
+ myint = 4
31
+
32
+
33
+ def _if_in_fstring_comprehension_with_elif(
34
+ params: Union[Sequence[Any], Mapping[str, Any]]
35
+ ):
36
+ order = {}
37
+ if "z" not in "false":
38
+ raise TypeError(
39
+ f" {', '.join(sorted(i for i in order or () if i not in params))}"
40
+ )
41
+ elif "z" not in "true":
42
+ pass
43
+ else:
44
+ if "t" not in "false": # [else-if-used]
45
+ raise TypeError("d")
46
+ else:
47
+ if "y" in "life": # [else-if-used]
48
+ print("e")
testbed/pylint-dev__pylint/tests/functional/ext/check_elif/check_elif.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.check_elif,
testbed/pylint-dev__pylint/tests/functional/ext/check_elif/check_elif.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ else-if-used:13:8:30:25:my_function:"Consider using ""elif"" instead of ""else"" then ""if"" to remove one indentation level":HIGH
2
+ else-if-used:25:20:26:28:my_function:"Consider using ""elif"" instead of ""else"" then ""if"" to remove one indentation level":HIGH
3
+ else-if-used:44:8:48:26:_if_in_fstring_comprehension_with_elif:"Consider using ""elif"" instead of ""else"" then ""if"" to remove one indentation level":HIGH
4
+ else-if-used:47:12:48:26:_if_in_fstring_comprehension_with_elif:"Consider using ""elif"" instead of ""else"" then ""if"" to remove one indentation level":HIGH
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_assignment_expr.py ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pylint: disable=missing-docstring,invalid-name,undefined-variable,too-few-public-methods
2
+
3
+ a1 = 2
4
+ if a1: # [consider-using-assignment-expr]
5
+ ...
6
+
7
+ # Do not suggest assignment expressions if assignment spans multiple lines
8
+ a2 = (
9
+ 1,
10
+ )
11
+ if a2:
12
+ ...
13
+
14
+ # Only first name should be replaced
15
+ a3 = 2
16
+ if a3 == a3_a: # [consider-using-assignment-expr]
17
+ ...
18
+
19
+ # Above black line length
20
+ a4 = some_loooooooonnnnnngggg_object_name.with_some_really_long_function_name(arg)
21
+ if a4:
22
+ ...
23
+
24
+ def func_a():
25
+ a5 = some___object.function_name_is_just_long_enough_to_fit_in_line() # some comment
26
+ if a5 is None: # [consider-using-assignment-expr]
27
+ ...
28
+
29
+ # Using assignment expression would result in line being 89 chars long
30
+ a6 = some_long_object.function_name_is_too_long_enough_to_fit___line()
31
+ if a6 is None:
32
+ ...
33
+
34
+ # Previous unrelate note should not match
35
+ print("")
36
+ if a7:
37
+ ...
38
+
39
+
40
+ b1: int = 2
41
+ if b1: # [consider-using-assignment-expr]
42
+ ...
43
+
44
+ b2 = some_function(2, 3)
45
+ if b2: # [consider-using-assignment-expr]
46
+ ...
47
+
48
+ b3 = some_object.variable
49
+ if b3: # [consider-using-assignment-expr]
50
+ ...
51
+
52
+
53
+ # UnaryOp
54
+ c1 = 2
55
+ if not c1: # [consider-using-assignment-expr]
56
+ ...
57
+
58
+
59
+ # Compare
60
+ d1 = 2
61
+ if d1 is True: # [consider-using-assignment-expr]
62
+ ...
63
+
64
+ d2 = 2
65
+ if d2 is not None: # [consider-using-assignment-expr]
66
+ ...
67
+
68
+ d3 = 2
69
+ if d3 == 2: # [consider-using-assignment-expr]
70
+ ...
71
+
72
+
73
+ # -----
74
+ # Don't emit warning if match statement would be a better fit
75
+ o1 = 2
76
+ if o1 == 1:
77
+ ...
78
+ elif o1 == 2:
79
+ ...
80
+ elif o1 == 3:
81
+ ...
82
+
83
+ o2 = 2
84
+ if o2 == 1:
85
+ ...
86
+ elif o2:
87
+ ...
88
+
89
+ o3 = 2
90
+ if o3 == 1: # [consider-using-assignment-expr]
91
+ ...
92
+ else:
93
+ ...
94
+
95
+ o4 = 2
96
+ if o4 == 1: # [consider-using-assignment-expr]
97
+ ...
98
+ elif o4 and o4_other:
99
+ ...
100
+
101
+ o5 = 2
102
+ if o5 == 1: # [consider-using-assignment-expr]
103
+ ...
104
+ elif o5_other == 1:
105
+ ...
106
+
107
+ o6 = 2
108
+ if o6 == 1: # [consider-using-assignment-expr]
109
+ ...
110
+ elif o6_other:
111
+ ...
112
+
113
+ def func_p():
114
+ p1 = 2
115
+ if p1 == 1:
116
+ return
117
+ if p1 == 2:
118
+ return
119
+
120
+ p2 = 2
121
+ if p2 == 1:
122
+ return
123
+ if p2:
124
+ return
125
+
126
+ p3 = 2
127
+ if p3 == 1: # [consider-using-assignment-expr]
128
+ ...
129
+ else:
130
+ ...
131
+
132
+ p4 = 2
133
+ if p4 == 1: # [consider-using-assignment-expr]
134
+ ...
135
+ elif p4 and p4_other:
136
+ ...
137
+
138
+ p5 = 2
139
+ if p5 == 1: # [consider-using-assignment-expr]
140
+ ...
141
+ elif p5_other == 1:
142
+ ...
143
+
144
+ p6 = 2
145
+ if p6 == 1: # [consider-using-assignment-expr]
146
+ ...
147
+ elif p6_other:
148
+ ...
149
+
150
+
151
+ # -----
152
+ # Assignment expression does NOT work for attribute access
153
+ # Make sure not to emit message!
154
+ class A:
155
+ var = 1
156
+
157
+ A.var = 2
158
+ if A.var:
159
+ ...
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_assignment_expr.rc ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.code_style
3
+ py-version=3.8
4
+
5
+ [CODE_STYLE]
6
+ max-line-length-suggestions=88
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_assignment_expr.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ consider-using-assignment-expr:4:3:4:5::"Use 'if (a1 := 2):' instead":UNDEFINED
2
+ consider-using-assignment-expr:16:3:16:5::"Use 'if (a3 := 2) == a3_a:' instead":UNDEFINED
3
+ consider-using-assignment-expr:26:7:26:9:func_a:"Use 'if (a5 := some___object.function_name_is_just_long_enough_to_fit_in_line()) is None:' instead":UNDEFINED
4
+ consider-using-assignment-expr:41:3:41:5::"Use 'if (b1 := 2):' instead":UNDEFINED
5
+ consider-using-assignment-expr:45:3:45:5::"Use 'if (b2 := some_function(2, 3)):' instead":UNDEFINED
6
+ consider-using-assignment-expr:49:3:49:5::"Use 'if (b3 := some_object.variable):' instead":UNDEFINED
7
+ consider-using-assignment-expr:55:7:55:9::"Use 'if not (c1 := 2):' instead":UNDEFINED
8
+ consider-using-assignment-expr:61:3:61:5::"Use 'if (d1 := 2) is True:' instead":UNDEFINED
9
+ consider-using-assignment-expr:65:3:65:5::"Use 'if (d2 := 2) is not None:' instead":UNDEFINED
10
+ consider-using-assignment-expr:69:3:69:5::"Use 'if (d3 := 2) == 2:' instead":UNDEFINED
11
+ consider-using-assignment-expr:90:3:90:5::"Use 'if (o3 := 2) == 1:' instead":UNDEFINED
12
+ consider-using-assignment-expr:96:3:96:5::"Use 'if (o4 := 2) == 1:' instead":UNDEFINED
13
+ consider-using-assignment-expr:102:3:102:5::"Use 'if (o5 := 2) == 1:' instead":UNDEFINED
14
+ consider-using-assignment-expr:108:3:108:5::"Use 'if (o6 := 2) == 1:' instead":UNDEFINED
15
+ consider-using-assignment-expr:127:7:127:9:func_p:"Use 'if (p3 := 2) == 1:' instead":UNDEFINED
16
+ consider-using-assignment-expr:133:7:133:9:func_p:"Use 'if (p4 := 2) == 1:' instead":UNDEFINED
17
+ consider-using-assignment-expr:139:7:139:9:func_p:"Use 'if (p5 := 2) == 1:' instead":UNDEFINED
18
+ consider-using-assignment-expr:145:7:145:9:func_p:"Use 'if (p6 := 2) == 1:' instead":UNDEFINED
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_augmented_assign.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for consider-using-augmented-assign."""
2
+
3
+ # pylint: disable=invalid-name,too-few-public-methods,import-error,consider-using-f-string,missing-docstring
4
+
5
+ from unknown import Unknown
6
+
7
+ x = 1
8
+
9
+ # summation is commutative (for integer and float, but not for string)
10
+ x = x + 3 # [consider-using-augmented-assign]
11
+ x = 3 + x # [consider-using-augmented-assign]
12
+ x = x + "3" # [consider-using-augmented-assign]
13
+ x = "3" + x
14
+
15
+ # We don't warn on intricate expressions as we lack knowledge of simplifying such
16
+ # expressions which is necessary to see if they can become augmented
17
+ x, y = 1 + x, 2 + x
18
+ x = 1 + x - 2
19
+ x = 1 + x + 2
20
+
21
+ # For anything other than a float or an int we only want to warn on
22
+ # assignments where the 'itself' is on the left side of the assignment
23
+ my_list = [2, 3, 4]
24
+ my_list = [1] + my_list
25
+
26
+
27
+ class MyClass:
28
+ """Simple base class."""
29
+
30
+ def __init__(self) -> None:
31
+ self.x = 1
32
+ self.x = self.x + 1 # [consider-using-augmented-assign]
33
+ self.x = 1 + self.x # [consider-using-augmented-assign]
34
+
35
+ x = 1 # [redefined-outer-name]
36
+ self.x = x
37
+
38
+
39
+ instance = MyClass()
40
+
41
+ x = instance.x + 1
42
+
43
+ my_str = ""
44
+ my_str = my_str + "foo" # [consider-using-augmented-assign]
45
+ my_str = "foo" + my_str
46
+
47
+ my_bytes = b""
48
+ my_bytes = my_bytes + b"foo" # [consider-using-augmented-assign]
49
+ my_bytes = b"foo" + my_bytes
50
+
51
+
52
+ def return_str() -> str:
53
+ """Return a string."""
54
+ return ""
55
+
56
+
57
+ # Currently we disregard all calls
58
+ my_str = return_str() + my_str
59
+ my_str = my_str % return_str()
60
+ my_str = my_str % 1 # [consider-using-augmented-assign]
61
+ my_str = my_str % (1, 2) # [consider-using-augmented-assign]
62
+ my_str = "%s" % my_str
63
+ my_str = return_str() % my_str
64
+ my_str = Unknown % my_str
65
+ my_str = my_str % Unknown # [consider-using-augmented-assign]
66
+
67
+ # subtraction is anti-commutative
68
+ x = x - 3 # [consider-using-augmented-assign]
69
+ x = 3 - x
70
+
71
+ # multiplication is commutative
72
+ x = x * 3 # [consider-using-augmented-assign]
73
+ x = 3 * x # [consider-using-augmented-assign]
74
+
75
+ # division is not commutative
76
+ x = x / 3 # [consider-using-augmented-assign]
77
+ x = 3 / x
78
+
79
+ # integer division is not commutative
80
+ x = x // 3 # [consider-using-augmented-assign]
81
+ x = 3 // x
82
+
83
+ # Left shift operator is not commutative
84
+ x = x << 3 # [consider-using-augmented-assign]
85
+ x = 3 << x
86
+
87
+ # Right shift operator is not commutative
88
+ x = x >> 3 # [consider-using-augmented-assign]
89
+ x = 3 >> x
90
+
91
+ # modulo is not commutative
92
+ x = x % 3 # [consider-using-augmented-assign]
93
+ x = 3 % x
94
+
95
+ # exponential is not commutative
96
+ x = x**3 # [consider-using-augmented-assign]
97
+ x = 3**x
98
+
99
+ # XOR is commutative
100
+ x = x ^ 3 # [consider-using-augmented-assign]
101
+ x = 3 ^ x # [consider-using-augmented-assign]
102
+
103
+ # Bitwise AND operator is commutative
104
+ x = x & 3 # [consider-using-augmented-assign]
105
+ x = 3 & x # [consider-using-augmented-assign]
106
+
107
+ # Bitwise OR operator is commutative
108
+ x = x | 3 # [consider-using-augmented-assign]
109
+ x = 3 | x # [consider-using-augmented-assign]
110
+
111
+ x = x > 3
112
+ x = 3 > x
113
+
114
+ x = x < 3
115
+ x = 3 < x
116
+
117
+ x = x >= 3
118
+ x = 3 >= x
119
+
120
+ x = x <= 3
121
+ x = 3 <= x
122
+
123
+
124
+ # https://github.com/PyCQA/pylint/issues/8086
125
+ # consider-using-augmented-assign should only be flagged
126
+ # if names attribute names match exactly.
127
+
128
+ class A:
129
+ def __init__(self) -> None:
130
+ self.a = 1
131
+ self.b = A()
132
+
133
+ def test(self) -> None:
134
+ self.a = self.a + 1 # [consider-using-augmented-assign]
135
+ self.b.a = self.a + 1 # Names don't match!
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_augmented_assign.rc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.code_style
3
+ enable=consider-using-augmented-assign
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_augmented_assign.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ consider-using-augmented-assign:10:0:10:9::Use '+=' to do an augmented assign directly:INFERENCE
2
+ consider-using-augmented-assign:11:0:11:9::Use '+=' to do an augmented assign directly:INFERENCE
3
+ consider-using-augmented-assign:12:0:12:11::Use '+=' to do an augmented assign directly:INFERENCE
4
+ consider-using-augmented-assign:32:8:32:27:MyClass.__init__:Use '+=' to do an augmented assign directly:INFERENCE
5
+ consider-using-augmented-assign:33:8:33:27:MyClass.__init__:Use '+=' to do an augmented assign directly:INFERENCE
6
+ redefined-outer-name:35:8:35:9:MyClass.__init__:Redefining name 'x' from outer scope (line 7):UNDEFINED
7
+ consider-using-augmented-assign:44:0:44:23::Use '+=' to do an augmented assign directly:INFERENCE
8
+ consider-using-augmented-assign:48:0:48:28::Use '+=' to do an augmented assign directly:INFERENCE
9
+ consider-using-augmented-assign:60:0:60:19::Use '%=' to do an augmented assign directly:INFERENCE
10
+ consider-using-augmented-assign:61:0:61:24::Use '%=' to do an augmented assign directly:INFERENCE
11
+ consider-using-augmented-assign:65:0:65:25::Use '%=' to do an augmented assign directly:INFERENCE
12
+ consider-using-augmented-assign:68:0:68:9::Use '-=' to do an augmented assign directly:INFERENCE
13
+ consider-using-augmented-assign:72:0:72:9::Use '*=' to do an augmented assign directly:INFERENCE
14
+ consider-using-augmented-assign:73:0:73:9::Use '*=' to do an augmented assign directly:INFERENCE
15
+ consider-using-augmented-assign:76:0:76:9::Use '/=' to do an augmented assign directly:INFERENCE
16
+ consider-using-augmented-assign:80:0:80:10::Use '//=' to do an augmented assign directly:INFERENCE
17
+ consider-using-augmented-assign:84:0:84:10::Use '<<=' to do an augmented assign directly:INFERENCE
18
+ consider-using-augmented-assign:88:0:88:10::Use '>>=' to do an augmented assign directly:INFERENCE
19
+ consider-using-augmented-assign:92:0:92:9::Use '%=' to do an augmented assign directly:INFERENCE
20
+ consider-using-augmented-assign:96:0:96:8::Use '**=' to do an augmented assign directly:INFERENCE
21
+ consider-using-augmented-assign:100:0:100:9::Use '^=' to do an augmented assign directly:INFERENCE
22
+ consider-using-augmented-assign:101:0:101:9::Use '^=' to do an augmented assign directly:INFERENCE
23
+ consider-using-augmented-assign:104:0:104:9::Use '&=' to do an augmented assign directly:INFERENCE
24
+ consider-using-augmented-assign:105:0:105:9::Use '&=' to do an augmented assign directly:INFERENCE
25
+ consider-using-augmented-assign:108:0:108:9::Use '|=' to do an augmented assign directly:INFERENCE
26
+ consider-using-augmented-assign:109:0:109:9::Use '|=' to do an augmented assign directly:INFERENCE
27
+ consider-using-augmented-assign:134:8:134:27:A.test:Use '+=' to do an augmented assign directly:INFERENCE
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_namedtuple_or_dataclass.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pylint: disable=missing-docstring,too-few-public-methods,unused-variable,no-name-in-module
2
+ from typing import Final
3
+
4
+ class Foo:
5
+ BAR = "bar"
6
+
7
+ KEY_3 = "key_3"
8
+
9
+
10
+ # Subdicts have at least 1 common key
11
+ MAPPING_1 = { # [consider-using-namedtuple-or-dataclass]
12
+ "entry_1": {"key_1": 0, "key_2": 1, "key_diff_1": 2},
13
+ "entry_2": {"key_1": 0, "key_2": 1, "key_diff_2": 3},
14
+ }
15
+ MAPPING_2 = { # [consider-using-namedtuple-or-dataclass]
16
+ "entry_1": {KEY_3: None, Foo.BAR: None},
17
+ "entry_2": {KEY_3: None, Foo.BAR: None},
18
+ }
19
+
20
+ # ints are not valid fieldnames for namedtuples
21
+ MAPPING_3 = {
22
+ "entry_1": {0: None, 1: None},
23
+ "entry_2": {0: None, 1: None},
24
+ }
25
+
26
+ # Subdicts have no common keys
27
+ MAPPING_4 = {
28
+ "entry_1": {"key_3": 0, "key_4": 1, "key_diff_1": 2},
29
+ "entry_2": {"key_1": 0, "key_2": 1, "key_diff_2": 3},
30
+ }
31
+
32
+ def func():
33
+ # Not in module scope
34
+ mapping_4 = {
35
+ "entry_1": {"key_1": 0, "key_2": 1},
36
+ "entry_2": {"key_1": 0, "key_2": 1},
37
+ }
38
+
39
+ mapping_5: Final = { # [consider-using-namedtuple-or-dataclass]
40
+ "entry_1": {"key_1": 0, "key_2": 1},
41
+ "entry_2": {"key_1": 0, "key_2": 1},
42
+ }
43
+
44
+
45
+ # lists must have the same length
46
+ MAPPING_6 = { # [consider-using-namedtuple-or-dataclass]
47
+ "entry_1": [1, "a", set()],
48
+ "entry_2": [2, "b", set()],
49
+ }
50
+ MAPPING_7 = {
51
+ "entry_1": [],
52
+ "entry_2": [],
53
+ }
54
+ MAPPING_8 = {
55
+ "entry_1": [1],
56
+ "entry_2": [2, "b"],
57
+ }
58
+ MAPPING_9 = { # [consider-using-namedtuple-or-dataclass]
59
+ "entry_1": (1, "a"),
60
+ "entry_2": (2, "b"),
61
+ }
62
+
63
+ # No entry can't contain only dicts
64
+ MAPPING_10 = {
65
+ "entry_1": [
66
+ {"key_1": None, "key_2": None},
67
+ ],
68
+ "entry_2": [None]
69
+ }
70
+
71
+ # No either dict, tuple, or list as dict values
72
+ MAPPING_11 = {
73
+ "entry_1": 1,
74
+ "entry_2": 2,
75
+ }
76
+ MAPPING_12 = {
77
+ "entry_1": "",
78
+ "entry_2": "",
79
+ }
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_namedtuple_or_dataclass.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.code_style
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_namedtuple_or_dataclass.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ consider-using-namedtuple-or-dataclass:11:12:14:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
2
+ consider-using-namedtuple-or-dataclass:15:12:18:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
3
+ consider-using-namedtuple-or-dataclass:39:23:42:5:func:Consider using namedtuple or dataclass for dictionary values:UNDEFINED
4
+ consider-using-namedtuple-or-dataclass:46:12:49:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
5
+ consider-using-namedtuple-or-dataclass:58:12:61:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_tuple.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pylint: disable=invalid-name,missing-docstring,pointless-statement,unnecessary-comprehension
2
+
3
+ var = (1, 2, 3)
4
+
5
+ for x in var:
6
+ pass
7
+ for x in (1, 2, 3):
8
+ pass
9
+ for x in [1, 2, 3]: # [consider-using-tuple]
10
+ pass
11
+
12
+ (x for x in var)
13
+ (x for x in (1, 2, 3))
14
+ (x for x in [1, 2, 3]) # [consider-using-tuple]
15
+
16
+ [x for x in var]
17
+ [x for x in (1, 2, 3)]
18
+ [x for x in [1, 2, 3]] # [consider-using-tuple]
19
+
20
+
21
+ for x in [*var]: # [consider-using-tuple]
22
+ pass
23
+ for x in [2, *var]: # [consider-using-tuple]
24
+ pass
25
+
26
+ [x for x in [*var, 2]] # [consider-using-tuple]
27
+
28
+
29
+ # Don't emit warning for sets as this is handled by builtin checker
30
+ (x for x in {1, 2, 3}) # [use-sequence-for-iteration]
31
+ [x for x in {*var, 2}]
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_tuple.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.code_style
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_consider_using_tuple.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ consider-using-tuple:9:9:9:18::Consider using an in-place tuple instead of list:UNDEFINED
2
+ consider-using-tuple:14:12:14:21::Consider using an in-place tuple instead of list:UNDEFINED
3
+ consider-using-tuple:18:12:18:21::Consider using an in-place tuple instead of list:UNDEFINED
4
+ consider-using-tuple:21:9:21:15::Consider using an in-place tuple instead of list:UNDEFINED
5
+ consider-using-tuple:23:9:23:18::Consider using an in-place tuple instead of list:UNDEFINED
6
+ consider-using-tuple:26:12:26:21::Consider using an in-place tuple instead of list:UNDEFINED
7
+ use-sequence-for-iteration:30:12:30:21::Use a sequence type when iterating over values:HIGH
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_default.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ """Test default configuration for code-style checker."""
2
+ # pylint: disable=invalid-name
3
+
4
+ # consider-using-augmented-assign is disabled by default
5
+ x = 1
6
+ x = x + 1
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_default.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.code_style
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_py_version_35.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ """No warnings should be emitted for features that require Python > 3.5"""
2
+ # pylint: disable=invalid-name
3
+
4
+ # consider-using-assignment-expr -> requires Python 3.8
5
+ a1 = 2
6
+ if a1:
7
+ ...
testbed/pylint-dev__pylint/tests/functional/ext/code_style/cs_py_version_35.rc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.code_style
3
+ py-version=3.5
testbed/pylint-dev__pylint/tests/functional/ext/comparison_placement/misplaced_comparison_constant.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Check that the constants are on the right side of the comparisons"""
2
+
3
+ # pylint: disable=singleton-comparison, missing-docstring, too-few-public-methods
4
+ # pylint: disable=comparison-of-constants
5
+
6
+ class MyClass:
7
+ def __init__(self):
8
+ self.attr = 1
9
+
10
+ def dummy_return(self):
11
+ return self.attr
12
+
13
+ def dummy_return():
14
+ return 2
15
+
16
+ def bad_comparisons():
17
+ """this is not ok"""
18
+ instance = MyClass()
19
+ for i in range(10):
20
+ if 5 <= i: # [misplaced-comparison-constant]
21
+ pass
22
+ if 1 == i: # [misplaced-comparison-constant]
23
+ pass
24
+ if 3 < dummy_return(): # [misplaced-comparison-constant]
25
+ pass
26
+ if 4 != instance.dummy_return(): # [misplaced-comparison-constant]
27
+ pass
28
+ if 1 == instance.attr: # [misplaced-comparison-constant]
29
+ pass
30
+ if "aaa" == instance.attr: # [misplaced-comparison-constant]
31
+ pass
32
+
33
+ def good_comparison():
34
+ """this is ok"""
35
+ for i in range(10):
36
+ if i == 5:
37
+ pass
38
+
39
+ def double_comparison():
40
+ """Check that we return early for non-binary comparison"""
41
+ for i in range(10):
42
+ if i == 1 == 2:
43
+ pass
44
+ if 2 <= i <= 8:
45
+ print("Between 2 and 8 inclusive")
46
+
47
+ def const_comparison():
48
+ """Check that we return early for comparison of two constants"""
49
+ if 1 == 2:
50
+ pass
testbed/pylint-dev__pylint/tests/functional/ext/comparison_placement/misplaced_comparison_constant.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.comparison_placement,
testbed/pylint-dev__pylint/tests/functional/ext/comparison_placement/misplaced_comparison_constant.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ misplaced-comparison-constant:20:11:20:17:bad_comparisons:Comparison should be i >= 5:UNDEFINED
2
+ misplaced-comparison-constant:22:11:22:17:bad_comparisons:Comparison should be i == 1:UNDEFINED
3
+ misplaced-comparison-constant:24:11:24:29:bad_comparisons:Comparison should be dummy_return() > 3:UNDEFINED
4
+ misplaced-comparison-constant:26:11:26:39:bad_comparisons:Comparison should be instance.dummy_return() != 4:UNDEFINED
5
+ misplaced-comparison-constant:28:11:28:29:bad_comparisons:Comparison should be instance.attr == 1:UNDEFINED
6
+ misplaced-comparison-constant:30:11:30:33:bad_comparisons:Comparison should be instance.attr == 'aaa':UNDEFINED
testbed/pylint-dev__pylint/tests/functional/ext/confusing_elif/confusing_elif.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pylint: disable=missing-module-docstring, missing-function-docstring
2
+
3
+
4
+ def triggered_if_if_block_ends_with_elif(machine, old_conf, new_conf):
5
+ """Example code that will trigger the message
6
+
7
+ Given an if-elif construct
8
+ When the body of the if ends with an elif
9
+ Then the message confusing-consecutive-elif must be triggered.
10
+ """
11
+ if old_conf:
12
+ if not new_conf:
13
+ machine.disable()
14
+ elif old_conf.value != new_conf.value:
15
+ machine.disable()
16
+ machine.enable(new_conf.value)
17
+ elif new_conf: # [confusing-consecutive-elif]
18
+ machine.enable(new_conf.value)
19
+
20
+
21
+ def not_triggered_if_indented_block_ends_with_else(machine, old_conf, new_conf):
22
+ """Example code must not trigger the message, because the inner block ends with else.
23
+
24
+ Given an if-elif construct
25
+ When the body of the if ends with an else
26
+ Then no message shall be triggered.
27
+ """
28
+ if old_conf:
29
+ if not new_conf:
30
+ machine.disable()
31
+ elif old_conf.value != new_conf.value:
32
+ machine.disable()
33
+ machine.enable(new_conf.value)
34
+ else:
35
+ pass
36
+ elif new_conf:
37
+ machine.enable(new_conf.value)
38
+
39
+
40
+ def not_triggered_if_indentend_block_ends_with_call(machine, old_conf, new_conf):
41
+ """
42
+ Example code must not trigger the message,
43
+
44
+ Given an if-elif construct
45
+ When the body of the if ends with a function call
46
+ Then no message shall be triggered.
47
+
48
+ Note: There is nothing special about the body ending with a function call.
49
+ This is just taken as a representative value for the equivalence class of
50
+ "every node class unrelated to if/elif/else".
51
+ """
52
+ if old_conf:
53
+ if not new_conf:
54
+ machine.disable()
55
+ elif old_conf.value != new_conf.value:
56
+ machine.disable()
57
+ machine.enable(new_conf.value)
58
+ print("Processed old configuration...")
59
+ elif new_conf:
60
+ machine.enable(new_conf.value)
61
+
62
+
63
+ def triggered_if_elif_block_ends_with_elif(machine, old_conf, new_conf, new_new_conf):
64
+ """Example code that will trigger the message
65
+
66
+ Given an if-elif-elif construct
67
+ When the body of the first elif ends with an elif
68
+ Then the message confusing-consecutive-elif must be triggered.
69
+ """
70
+ if old_conf:
71
+ machine.disable()
72
+ elif not new_conf:
73
+ if new_new_conf:
74
+ machine.disable()
75
+ elif old_conf.value != new_conf.value:
76
+ machine.disable()
77
+ machine.enable(new_conf.value)
78
+ elif new_conf: # [confusing-consecutive-elif]
79
+ machine.enable(new_conf.value)
80
+
81
+
82
+ def triggered_if_block_ends_with_if(machine, old_conf, new_conf, new_new_conf):
83
+ """Example code that will trigger the message
84
+
85
+ Given an if-elif construct
86
+ When the body of the if ends with an if
87
+ Then the message confusing-consecutive-elif must be triggered.
88
+ """
89
+ if old_conf:
90
+ if new_new_conf:
91
+ machine.disable()
92
+ elif new_conf: # [confusing-consecutive-elif]
93
+ machine.enable(new_conf.value)
94
+
95
+
96
+ def not_triggered_if_indented_block_ends_with_ifexp(machine, old_conf, new_conf):
97
+ """
98
+ Example code must not trigger the message,
99
+
100
+ Given an if-elif construct
101
+ When the body of the if ends with an if expression
102
+ Then no message shall be triggered.
103
+ """
104
+ if old_conf:
105
+ if not new_conf:
106
+ machine.disable()
107
+ print("Processed old configuration...")
108
+ elif new_conf:
109
+ machine.enable(new_conf.value)
110
+
111
+
112
+ def not_triggered_if_outer_block_does_not_have_elif(machine, old_conf, new_conf):
113
+ """Example code must not trigger the message
114
+
115
+ Given an if construct without an elif
116
+ When the body of the if ends with an if
117
+ Then no message shall be triggered.
118
+ """
119
+ if old_conf:
120
+ if not new_conf:
121
+ machine.disable()
122
+ elif old_conf.value != new_conf.value:
123
+ machine.disable()
124
+ machine.enable(new_conf.value)
125
+ else:
126
+ pass
127
+
128
+
129
+ def not_triggered_if_outer_block_continues_with_if(machine, old_conf, new_conf, new_new_conf):
130
+ """Example code that will trigger the message
131
+
132
+ Given an if construct which continues with a new if construct
133
+ When the body of the first if ends with an if expression
134
+ Then no message shall be triggered.
135
+ """
136
+ if old_conf:
137
+ if new_new_conf:
138
+ machine.disable()
139
+ elif old_conf.value != new_conf.value:
140
+ machine.disable()
141
+ machine.enable(new_conf.value)
142
+ if new_conf:
143
+ machine.enable(new_conf.value)
testbed/pylint-dev__pylint/tests/functional/ext/confusing_elif/confusing_elif.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.confusing_elif
testbed/pylint-dev__pylint/tests/functional/ext/confusing_elif/confusing_elif.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ confusing-consecutive-elif:17:4:18:38:triggered_if_if_block_ends_with_elif:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif:UNDEFINED
2
+ confusing-consecutive-elif:78:4:79:38:triggered_if_elif_block_ends_with_elif:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif:UNDEFINED
3
+ confusing-consecutive-elif:92:4:93:38:triggered_if_block_ends_with_if:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif:UNDEFINED
testbed/pylint-dev__pylint/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pylint: disable=invalid-name, undefined-variable, unused-variable, missing-function-docstring, missing-module-docstring
2
+ # pylint: disable=unsupported-assignment-operation, line-too-long
3
+
4
+ if f(): # [consider-ternary-expression]
5
+ x = 4
6
+ else:
7
+ x = 5
8
+
9
+ if g():
10
+ y = 3
11
+ elif h():
12
+ y = 4
13
+ else:
14
+ y = 5
15
+
16
+ def a():
17
+ if i(): # [consider-ternary-expression]
18
+ z = 4
19
+ else:
20
+ z = 5
21
+
22
+ if f():
23
+ x = 4
24
+ print(x)
25
+ else:
26
+ x = 5
27
+
28
+ if f():
29
+ x[0] = 4
30
+ else:
31
+ x = 5
32
+
33
+ if f():
34
+ x = 4
35
+ else:
36
+ y = 5
testbed/pylint-dev__pylint/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.rc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.consider_ternary_expression,
testbed/pylint-dev__pylint/tests/functional/ext/consider_ternary_expression/consider_ternary_expression.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ consider-ternary-expression:4:0:7:9::Consider rewriting as a ternary expression:UNDEFINED
2
+ consider-ternary-expression:17:4:20:13:a:Consider rewriting as a ternary expression:UNDEFINED
testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Fixture for testing missing documentation in docparams."""
2
+ # pylint: disable=broad-exception-raised
3
+
4
+ def _private_func1( # [missing-return-doc, missing-return-type-doc, missing-any-param-doc]
5
+ param1,
6
+ ):
7
+ """This is a test docstring without returns"""
8
+ return param1
9
+
10
+
11
+ def _private_func2( # [missing-yield-doc, missing-yield-type-doc, missing-any-param-doc]
12
+ param1,
13
+ ):
14
+ """This is a test docstring without yields"""
15
+ yield param1
16
+
17
+
18
+ def _private_func3(param1): # [missing-raises-doc, missing-any-param-doc]
19
+ """This is a test docstring without raises"""
20
+ raise Exception("Example")
21
+
22
+
23
+ def public_func1(param1): # [missing-any-param-doc]
24
+ """This is a test docstring without params"""
25
+ print(param1)
26
+
27
+
28
+ # pylint: disable-next=line-too-long
29
+ async def _async_private_func1( # [missing-return-doc, missing-return-type-doc, missing-any-param-doc]
30
+ param1,
31
+ ):
32
+ """This is a test docstring without returns"""
33
+ return param1
34
+
35
+
36
+ # pylint: disable-next=line-too-long
37
+ async def _async_private_func2( # [missing-yield-doc, missing-yield-type-doc, missing-any-param-doc]
38
+ param1,
39
+ ):
40
+ """This is a test docstring without yields"""
41
+ yield param1
42
+
43
+
44
+ async def _async_private_func3(param1): # [missing-raises-doc, missing-any-param-doc]
45
+ """This is a test docstring without raises"""
46
+ raise Exception("Example")
47
+
48
+
49
+ async def async_public_func1(param1): # [missing-any-param-doc]
50
+ """This is a test docstring without params"""
51
+ print(param1)
52
+
53
+
54
+ def differing_param_doc(par1: int) -> int: # [differing-param-doc]
55
+ """This is a test docstring documenting one non-existing param
56
+
57
+ :param par1: some param
58
+ :param param: some param
59
+ :return: the sum of the params
60
+ """
61
+
62
+ return par1
63
+
64
+
65
+ def differing_param_doc_kwords_only(*, par1: int) -> int: # [differing-param-doc]
66
+ """This is a test docstring documenting one non-existing param
67
+
68
+ :param par1: some param
69
+ :param param: some param
70
+ :return: the sum of the params
71
+ """
72
+
73
+ return par1
74
+
75
+
76
+ def missing_type_doc(par1) -> int: # [missing-type-doc]
77
+ """This is a test docstring params where the type is not specified
78
+
79
+ :param par1: some param
80
+ :return: the param
81
+ """
82
+
83
+ return par1
84
+
85
+
86
+ def missing_type_doc_kwords_only(*, par1) -> int: # [missing-type-doc]
87
+ """This is a test docstring params where the type is not specified
88
+
89
+ :param par1: some param
90
+ :return: the param
91
+ """
92
+
93
+ return par1
94
+
95
+
96
+ def params_are_documented(par1: int, *, par2: int) -> int:
97
+ """This is a test docstring params where nothing is raised as it is all documented
98
+
99
+ :param par1: some param
100
+ :param par2: some other param
101
+ :return: the sum of params
102
+ """
103
+
104
+ return par1 + par2
105
+
106
+
107
+ # Only check raise nodes within FunctionDefs
108
+ raise Exception()
testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams.rc ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ [MAIN]
2
+ load-plugins = pylint.extensions.docparams
3
+ no-docstring-rgx = ONLYVERYSPECIFICFUNCTIONS
4
+
5
+ [BASIC]
6
+ accept-no-param-doc = no
7
+ accept-no-raise-doc = no
8
+ accept-no-return-doc = no
9
+ accept-no-yields-doc = no
testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams.txt ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ missing-any-param-doc:4:0:4:18:_private_func1:"Missing any documentation in ""_private_func1""":HIGH
2
+ missing-return-doc:4:0:4:18:_private_func1:Missing return documentation:HIGH
3
+ missing-return-type-doc:4:0:4:18:_private_func1:Missing return type documentation:HIGH
4
+ missing-any-param-doc:11:0:11:18:_private_func2:"Missing any documentation in ""_private_func2""":HIGH
5
+ missing-yield-doc:11:0:11:18:_private_func2:Missing yield documentation:HIGH
6
+ missing-yield-type-doc:11:0:11:18:_private_func2:Missing yield type documentation:HIGH
7
+ missing-any-param-doc:18:0:18:18:_private_func3:"Missing any documentation in ""_private_func3""":HIGH
8
+ missing-raises-doc:18:0:18:18:_private_func3:"""Exception"" not documented as being raised":HIGH
9
+ missing-any-param-doc:23:0:23:16:public_func1:"Missing any documentation in ""public_func1""":HIGH
10
+ missing-any-param-doc:29:0:29:30:_async_private_func1:"Missing any documentation in ""_async_private_func1""":HIGH
11
+ missing-return-doc:29:0:29:30:_async_private_func1:Missing return documentation:HIGH
12
+ missing-return-type-doc:29:0:29:30:_async_private_func1:Missing return type documentation:HIGH
13
+ missing-any-param-doc:37:0:37:30:_async_private_func2:"Missing any documentation in ""_async_private_func2""":HIGH
14
+ missing-yield-doc:37:0:37:30:_async_private_func2:Missing yield documentation:HIGH
15
+ missing-yield-type-doc:37:0:37:30:_async_private_func2:Missing yield type documentation:HIGH
16
+ missing-any-param-doc:44:0:44:30:_async_private_func3:"Missing any documentation in ""_async_private_func3""":HIGH
17
+ missing-raises-doc:44:0:44:30:_async_private_func3:"""Exception"" not documented as being raised":HIGH
18
+ missing-any-param-doc:49:0:49:28:async_public_func1:"Missing any documentation in ""async_public_func1""":HIGH
19
+ differing-param-doc:54:0:54:23:differing_param_doc:"""param"" differing in parameter documentation":HIGH
20
+ differing-param-doc:65:0:65:35:differing_param_doc_kwords_only:"""param"" differing in parameter documentation":HIGH
21
+ missing-type-doc:76:0:76:20:missing_type_doc:"""par1"" missing in parameter type documentation":HIGH
22
+ missing-type-doc:86:0:86:32:missing_type_doc_kwords_only:"""par1"" missing in parameter type documentation":HIGH
testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams_py38.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Fixture for testing missing documentation in docparams (Python >=3.8 only)."""
2
+
3
+
4
+ def differing_param_doc_pos_only(par1: int, /) -> int: # [differing-param-doc]
5
+ """This is a test docstring documenting one non-existing param
6
+
7
+ :param par1: some param
8
+ :param param: some param
9
+ :return: the sum of the params
10
+ """
11
+
12
+ return par1
13
+
14
+
15
+ def missing_type_doc_pos_only(par1, /) -> int: # [missing-type-doc]
16
+ """This is a test docstring params where the type is not specified
17
+
18
+ :param par1: some param
19
+ :return: the param
20
+ """
21
+
22
+ return par1
23
+
24
+
25
+ def params_are_documented(par1: int, /, par2: int, *, par3: int) -> int:
26
+ """This is a test docstring params where nothing is raised as it is all documented
27
+
28
+ :param par1: some param
29
+ :param par2: some other param
30
+ :param par3: some other param
31
+ :return: the sum of params
32
+ """
33
+
34
+ return par1 + par2 + par3
testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams_py38.rc ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [MAIN]
2
+ load-plugins = pylint.extensions.docparams
3
+
4
+ [BASIC]
5
+ accept-no-param-doc = no
6
+ accept-no-raise-doc = no
7
+ accept-no-return-doc = no
8
+ accept-no-yields-doc = no
9
+
10
+ [testoptions]
11
+ min_pyver=3.8
testbed/pylint-dev__pylint/tests/functional/ext/docparams/docparams_py38.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ differing-param-doc:4:0:4:32:differing_param_doc_pos_only:"""param"" differing in parameter documentation":HIGH
2
+ missing-type-doc:15:0:15:29:missing_type_doc_pos_only:"""par1"" missing in parameter type documentation":HIGH
testbed/pylint-dev__pylint/tests/functional/ext/docparams/missing_param_doc.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pylint: disable=missing-module-docstring
2
+
3
+ def foobar1(arg1, arg2): #[missing-any-param-doc]
4
+ """function foobar ...
5
+ """
6
+ print(arg1, arg2)
7
+
8
+ def foobar2(arg1, arg2): #[missing-any-param-doc]
9
+ """function foobar ...
10
+ Parameters
11
+ ----------
12
+ """
13
+ print(arg1, arg2)
14
+
15
+ def foobar3(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc]
16
+ """function foobar ...
17
+ Parameters
18
+ ----------
19
+ arg1: int
20
+ arg3: float
21
+ """
22
+ print(arg1, arg2, arg3)
23
+
24
+ def foobar4(arg1, arg2): #[missing-param-doc, missing-type-doc]
25
+ """function foobar ...
26
+ Parameters
27
+ ----------
28
+ arg1: int
29
+ description
30
+ """
31
+ print(arg1, arg2)
32
+
33
+ def foobar5(arg1, arg2): #[missing-type-doc]
34
+ """function foobar ...
35
+ Parameters
36
+ ----------
37
+ arg1:
38
+ description
39
+ arg2: str
40
+ """
41
+ print(arg1, arg2)
42
+
43
+ def foobar6(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc]
44
+ """function foobar ...
45
+ Parameters
46
+ ----------
47
+ arg1: int
48
+ description
49
+ arg2: int
50
+ """
51
+ print(arg1, arg2, arg3)
52
+
53
+ def foobar7(arg1, arg2): #[missing-any-param-doc]
54
+ """function foobar ...
55
+ Parameters
56
+ ----------
57
+ arg1
58
+ """
59
+ print(arg1, arg2)
60
+
61
+ def foobar8(arg1): #[missing-any-param-doc]
62
+ """function foobar"""
63
+
64
+ print(arg1)
65
+
66
+ def foobar9(arg1, arg2, arg3):
67
+ """function foobar ...
68
+ Parameters
69
+ ----------
70
+ arg1: int
71
+ arg2: int
72
+ arg3: str
73
+ """
74
+ print(arg1, arg2, arg3)
75
+
76
+ def foobar10(arg1, arg2, arg3): #[missing-type-doc]
77
+ """function foobar ...
78
+ Parameters
79
+ ----------
80
+ arg1:
81
+ desc1
82
+ arg2: int
83
+ arg3:
84
+ desc3
85
+ """
86
+ print(arg1, arg2, arg3)
87
+
88
+ def foobar11(arg1, arg2): #[missing-any-param-doc]
89
+ """function foobar ...
90
+ Args
91
+ ----------
92
+ arg1
93
+ arg2
94
+ """
95
+ print(arg1, arg2)
96
+
97
+ def foobar12(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc]
98
+ """function foobar ...
99
+ Args
100
+ ----------
101
+ arg1: int
102
+ arg2:
103
+ does something
104
+ arg3
105
+ """
106
+ print(arg1, arg2, arg3)
107
+
108
+ def foobar13(arg1, *args, arg3=";"):
109
+ """Description of the function
110
+
111
+ Parameters
112
+ ----------
113
+ arg1 : str
114
+ Path to the input.
115
+ *args :
116
+ Relevant parameters.
117
+ arg3 : str, optional
118
+ File separator.
119
+ """
120
+ print(arg1, args, arg3)
121
+
122
+ def foobar14(arg1, *args):
123
+ """Description of the function
124
+
125
+ Parameters
126
+ ----------
127
+ arg1 : str
128
+ Path to the input.
129
+ *args :
130
+ Relevant parameters.
131
+ """
132
+ print(arg1, args)
133
+
134
+ def foobar15(*args):
135
+ """Description of the function
136
+
137
+ Parameters
138
+ ----------
139
+ *args :
140
+ Relevant parameters.
141
+ """
142
+ print(args)
testbed/pylint-dev__pylint/tests/functional/ext/docparams/missing_param_doc.rc ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ [MAIN]
2
+ load-plugins=pylint.extensions.docparams,
3
+
4
+ [PARAMETER_DOCUMENTATION]
5
+ accept-no-param-doc=no
6
+ accept-no-raise-doc=no
7
+ accept-no-return-doc=no
8
+ accept-no-yields-doc=no
testbed/pylint-dev__pylint/tests/functional/ext/docparams/missing_param_doc.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ missing-any-param-doc:3:0:3:11:foobar1:"Missing any documentation in ""foobar1""":HIGH
2
+ missing-any-param-doc:8:0:8:11:foobar2:"Missing any documentation in ""foobar2""":HIGH
3
+ missing-param-doc:15:0:15:11:foobar3:"""arg2"" missing in parameter documentation":HIGH
4
+ missing-type-doc:15:0:15:11:foobar3:"""arg2"" missing in parameter type documentation":HIGH
5
+ missing-param-doc:24:0:24:11:foobar4:"""arg2"" missing in parameter documentation":HIGH
6
+ missing-type-doc:24:0:24:11:foobar4:"""arg2"" missing in parameter type documentation":HIGH
7
+ missing-type-doc:33:0:33:11:foobar5:"""arg1"" missing in parameter type documentation":HIGH
8
+ missing-param-doc:43:0:43:11:foobar6:"""arg3"" missing in parameter documentation":HIGH
9
+ missing-type-doc:43:0:43:11:foobar6:"""arg3"" missing in parameter type documentation":HIGH
10
+ missing-any-param-doc:53:0:53:11:foobar7:"Missing any documentation in ""foobar7""":HIGH
11
+ missing-any-param-doc:61:0:61:11:foobar8:"Missing any documentation in ""foobar8""":HIGH
12
+ missing-type-doc:76:0:76:12:foobar10:"""arg1, arg3"" missing in parameter type documentation":HIGH
13
+ missing-any-param-doc:88:0:88:12:foobar11:"Missing any documentation in ""foobar11""":HIGH
14
+ missing-param-doc:97:0:97:12:foobar12:"""arg3"" missing in parameter documentation":HIGH
15
+ missing-type-doc:97:0:97:12:foobar12:"""arg2, arg3"" missing in parameter type documentation":HIGH
testbed/pylint-dev__pylint/tests/functional/ext/docparams/parameter/missing_param_doc.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for missing-param-doc and missing-type-doc for non-specified style docstrings
2
+ with accept-no-param-doc = yes
3
+ """
4
+ # pylint: disable=invalid-name, unused-argument
5
+
6
+
7
+ def test_tolerate_no_param_documentation_at_all(x, y):
8
+ """Example of a function with no parameter documentation at all
9
+
10
+ No error message is emitted.
11
+
12
+ missing parameter documentation"""
testbed/pylint-dev__pylint/tests/functional/ext/docparams/parameter/missing_param_doc.rc ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [MAIN]
2
+ load-plugins = pylint.extensions.docparams
3
+
4
+ [BASIC]
5
+ accept-no-param-doc=yes
6
+ docstring-min-length: -1
7
+ no-docstring-rgx=^$
testbed/pylint-dev__pylint/tests/functional/ext/docparams/parameter/missing_param_doc_required.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for missing-param-doc and missing-type-doc for non-specified style docstrings
2
+ with accept-no-param-doc = no
3
+ """
4
+ # pylint: disable=invalid-name, unused-argument, too-few-public-methods
5
+
6
+
7
+ def test_don_t_tolerate_no_param_documentation_at_all(x, y): # [missing-any-param-doc]
8
+ """Example of a function with no parameter documentation at all
9
+
10
+ Missing documentation error message is emitted.
11
+
12
+ missing parameter documentation"""
13
+
14
+
15
+ def test_see_tolerate_no_param_documentation_at_all(x, y):
16
+ """Example for the usage of "For the parameters, see"
17
+ to suppress missing-param warnings.
18
+
19
+ For the parameters, see :func:`blah`
20
+ """
21
+
22
+
23
+ class ClassFoo:
24
+ """Example usage of "For the parameters, see" in init docstring"""
25
+
26
+ def __init__(self, x, y):
27
+ """docstring foo constructor
28
+
29
+ For the parameters, see :func:`bla`
30
+ """
31
+
32
+
33
+ class ClassFooTwo:
34
+ """test_see_sentence_for_constr_params_in_class
35
+ Example usage of "For the parameters, see" in class docstring
36
+
37
+ For the parameters, see :func:`bla`
38
+ """
39
+
40
+ def __init__(self, x, y):
41
+ """init"""
42
+
43
+
44
+ def test_kwonlyargs_are_taken_in_account( # [missing-param-doc, missing-type-doc]
45
+ arg, *, kwonly, missing_kwonly
46
+ ):
47
+ """The docstring
48
+
49
+ :param int arg: The argument.
50
+ :param bool kwonly: A keyword-arg.
51
+ """
testbed/pylint-dev__pylint/tests/functional/ext/docparams/parameter/missing_param_doc_required.rc ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [MAIN]
2
+ load-plugins = pylint.extensions.docparams
3
+
4
+ [BASIC]
5
+ accept-no-param-doc=no
6
+ docstring-min-length: -1
7
+ no-docstring-rgx=^$