@@ -51,51 +51,71 @@ int argument_count(string name) {
51
51
}
52
52
53
53
predicate incorrect_special_method_defn (
54
- Function func , string message , boolean show_counts , string name
54
+ Function func , string message , boolean show_counts , string name , boolean is_unused_default
55
55
) {
56
56
exists ( int required | required = argument_count ( name ) |
57
57
/* actual_non_default <= actual */
58
58
if required > func .getMaxPositionalArguments ( )
59
- then message = "Too few parameters" and show_counts = true
59
+ then message = "Too few parameters" and show_counts = true and is_unused_default = false
60
60
else
61
61
if required < func .getMinPositionalArguments ( )
62
- then message = "Too many parameters" and show_counts = true
62
+ then message = "Too many parameters" and show_counts = true and is_unused_default = false
63
63
else (
64
64
func .getMinPositionalArguments ( ) < required and
65
65
not func .hasVarArg ( ) and
66
66
message =
67
67
( required - func .getMinPositionalArguments ( ) ) + " default values(s) will never be used" and
68
- show_counts = false
68
+ show_counts = false and
69
+ is_unused_default = true
69
70
)
70
71
)
71
72
}
72
73
73
- predicate incorrect_pow ( Function func , string message , boolean show_counts ) {
74
+ predicate incorrect_pow (
75
+ Function func , string message , boolean show_counts , boolean is_unused_default
76
+ ) {
74
77
(
75
- func .getMaxPositionalArguments ( ) < 2 and message = "Too few parameters" and show_counts = true
78
+ func .getMaxPositionalArguments ( ) < 2 and
79
+ message = "Too few parameters" and
80
+ show_counts = true and
81
+ is_unused_default = false
76
82
or
77
- func .getMinPositionalArguments ( ) > 3 and message = "Too many parameters" and show_counts = true
83
+ func .getMinPositionalArguments ( ) > 3 and
84
+ message = "Too many parameters" and
85
+ show_counts = true and
86
+ is_unused_default = false
78
87
or
79
88
func .getMinPositionalArguments ( ) < 2 and
80
89
message = ( 2 - func .getMinPositionalArguments ( ) ) + " default value(s) will never be used" and
81
- show_counts = false
90
+ show_counts = false and
91
+ is_unused_default = true
82
92
or
83
93
func .getMinPositionalArguments ( ) = 3 and
84
94
message = "Third parameter to __pow__ should have a default value" and
85
- show_counts = false
95
+ show_counts = false and
96
+ is_unused_default = false
86
97
)
87
98
}
88
99
89
- predicate incorrect_get ( Function func , string message , boolean show_counts ) {
100
+ predicate incorrect_get (
101
+ Function func , string message , boolean show_counts , boolean is_unused_default
102
+ ) {
90
103
(
91
- func .getMaxPositionalArguments ( ) < 3 and message = "Too few parameters" and show_counts = true
104
+ func .getMaxPositionalArguments ( ) < 3 and
105
+ message = "Too few parameters" and
106
+ show_counts = true and
107
+ is_unused_default = false
92
108
or
93
- func .getMinPositionalArguments ( ) > 3 and message = "Too many parameters" and show_counts = true
109
+ func .getMinPositionalArguments ( ) > 3 and
110
+ message = "Too many parameters" and
111
+ show_counts = true and
112
+ is_unused_default = false
94
113
or
95
114
func .getMinPositionalArguments ( ) < 2 and
96
115
not func .hasVarArg ( ) and
97
116
message = ( 2 - func .getMinPositionalArguments ( ) ) + " default value(s) will never be used" and
98
- show_counts = false
117
+ show_counts = false and
118
+ is_unused_default = true
99
119
)
100
120
}
101
121
@@ -117,16 +137,18 @@ string has_parameters(Function f) {
117
137
118
138
from
119
139
PythonFunctionValue f , string message , string sizes , boolean show_counts , string name ,
120
- ClassValue owner
140
+ ClassValue owner , boolean show_unused_defaults
121
141
where
122
142
owner .declaredAttribute ( name ) = f and
123
143
(
124
- incorrect_special_method_defn ( f .getScope ( ) , message , show_counts , name )
144
+ incorrect_special_method_defn ( f .getScope ( ) , message , show_counts , name , show_unused_defaults )
145
+ or
146
+ incorrect_pow ( f .getScope ( ) , message , show_counts , show_unused_defaults ) and name = "__pow__"
125
147
or
126
- incorrect_pow ( f .getScope ( ) , message , show_counts ) and name = "__pow__ "
148
+ incorrect_get ( f .getScope ( ) , message , show_counts , show_unused_defaults ) and name = "__get__ "
127
149
or
128
- incorrect_get ( f .getScope ( ) , message , show_counts ) and name = "__get__"
129
150
) and
151
+ show_unused_defaults = false and
130
152
(
131
153
show_counts = false and sizes = ""
132
154
or
0 commit comments