Skip to content

Commit ea5aa57

Browse files
authored
Merge pull request github#3031 from BekaValentine/python-objectapi-to-valueapi-signaturespecialmethods
Python: ObjectAPI to ValueAPI: SignatureSpecialMethods
2 parents dd0ce1c + e8708a0 commit ea5aa57

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

python/ql/src/Functions/SignatureSpecialMethods.ql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ predicate is_quad_op(string name) {
112112
name = "__setslice__" or name = "__exit__"
113113
}
114114

115-
int argument_count(PyFunctionObject f, string name, ClassObject cls) {
115+
int argument_count(PythonFunctionValue f, string name, ClassValue cls) {
116116
cls.declaredAttribute(name) = f and
117117
(
118118
is_unary_op(name) and result = 1
@@ -125,22 +125,22 @@ int argument_count(PyFunctionObject f, string name, ClassObject cls) {
125125
)
126126
}
127127

128-
predicate incorrect_special_method_defn(PyFunctionObject func, string message, boolean show_counts, string name, ClassObject owner) {
128+
predicate incorrect_special_method_defn(PythonFunctionValue func, string message, boolean show_counts, string name, ClassValue owner) {
129129
exists(int required |
130130
required = argument_count(func, name, owner) |
131131
/* actual_non_default <= actual */
132132
if required > func.maxParameters() then
133133
(message = "Too few parameters" and show_counts = true)
134134
else if required < func.minParameters() then
135135
(message = "Too many parameters" and show_counts = true)
136-
else if (func.minParameters() < required and not func.getFunction().hasVarArg()) then
136+
else if (func.minParameters() < required and not func.getScope().hasVarArg()) then
137137
(message = (required -func.minParameters()) + " default values(s) will never be used" and show_counts = false)
138138
else
139139
none()
140140
)
141141
}
142142

143-
predicate incorrect_pow(FunctionObject func, string message, boolean show_counts, ClassObject owner) {
143+
predicate incorrect_pow(FunctionValue func, string message, boolean show_counts, ClassValue owner) {
144144
owner.declaredAttribute("__pow__") = func and
145145
(
146146
func.maxParameters() < 2 and message = "Too few parameters" and show_counts = true
@@ -153,27 +153,27 @@ predicate incorrect_pow(FunctionObject func, string message, boolean show_counts
153153
)
154154
}
155155

156-
predicate incorrect_get(FunctionObject func, string message, boolean show_counts, ClassObject owner) {
156+
predicate incorrect_get(FunctionValue func, string message, boolean show_counts, ClassValue owner) {
157157
owner.declaredAttribute("__get__") = func and
158158
(
159159
func.maxParameters() < 3 and message = "Too few parameters" and show_counts = true
160160
or
161161
func.minParameters() > 3 and message = "Too many parameters" and show_counts = true
162162
or
163-
func.minParameters() < 2 and not func.getFunction().hasVarArg() and
163+
func.minParameters() < 2 and not func.getScope().hasVarArg() and
164164
message = (2 - func.minParameters()) + " default value(s) will never be used" and show_counts = false
165165
)
166166
}
167167

168-
string should_have_parameters(PyFunctionObject f, string name, ClassObject owner) {
168+
string should_have_parameters(PythonFunctionValue f, string name, ClassValue owner) {
169169
exists(int i | i = argument_count(f, name, owner) |
170170
result = i.toString()
171171
)
172172
or
173173
owner.declaredAttribute(name) = f and (name = "__get__" or name = "__pow__") and result = "2 or 3"
174174
}
175175

176-
string has_parameters(PyFunctionObject f) {
176+
string has_parameters(PythonFunctionValue f) {
177177
exists(int i | i = f.minParameters() |
178178
i = 0 and result = "no parameters"
179179
or
@@ -183,7 +183,7 @@ string has_parameters(PyFunctionObject f) {
183183
)
184184
}
185185

186-
from PyFunctionObject f, string message, string sizes, boolean show_counts, string name, ClassObject owner
186+
from PythonFunctionValue f, string message, string sizes, boolean show_counts, string name, ClassValue owner
187187
where
188188
(
189189
incorrect_special_method_defn(f, message, show_counts, name, owner)
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
| om_test.py:59:5:59:28 | Function __div__ | Too many parameters for special method __div__, which has 3 parameters, but should have 2, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
2-
| om_test.py:62:5:62:22 | Function __mul__ | Too few parameters for special method __mul__, which has 1 parameter, but should have 2, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
3-
| om_test.py:65:5:65:29 | Function __neg__ | Too many parameters for special method __neg__, which has 2 parameters, but should have 1, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
4-
| om_test.py:68:5:68:35 | Function __exit__ | Too few parameters for special method __exit__, which has 3 parameters, but should have 4, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
5-
| om_test.py:71:5:71:19 | Function __repr__ | Too few parameters for special method __repr__, which has no parameters, but should have 1, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
6-
| om_test.py:74:5:74:46 | Function __add__ | 1 default values(s) will never be used for special method __add__, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
7-
| om_test.py:97:15:97:34 | Function lambda | Too few parameters for special method __sub__, which has 1 parameter, but should have 2, in class $@. | om_test.py:95:1:95:28 | class NotOKSpecials | NotOKSpecials |
1+
| om_test.py:59:5:59:28 | Function WrongSpecials.__div__ | Too many parameters for special method __div__, which has 3 parameters, but should have 2, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
2+
| om_test.py:62:5:62:22 | Function WrongSpecials.__mul__ | Too few parameters for special method __mul__, which has 1 parameter, but should have 2, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
3+
| om_test.py:65:5:65:29 | Function WrongSpecials.__neg__ | Too many parameters for special method __neg__, which has 2 parameters, but should have 1, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
4+
| om_test.py:68:5:68:35 | Function WrongSpecials.__exit__ | Too few parameters for special method __exit__, which has 3 parameters, but should have 4, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
5+
| om_test.py:71:5:71:19 | Function WrongSpecials.__repr__ | Too few parameters for special method __repr__, which has no parameters, but should have 1, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
6+
| om_test.py:74:5:74:46 | Function WrongSpecials.__add__ | 1 default values(s) will never be used for special method __add__, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
7+
| om_test.py:97:15:97:34 | Function NotOKSpecials.lambda | Too few parameters for special method __sub__, which has 1 parameter, but should have 2, in class $@. | om_test.py:95:1:95:28 | class NotOKSpecials | NotOKSpecials |
88
| protocols.py:104:1:104:12 | Function f | Too few parameters for special method __add__, which has 1 parameter, but should have 2, in class $@. | protocols.py:107:1:107:29 | class MissingMethods | MissingMethods |
99
| protocols.py:104:1:104:12 | Function f | Too few parameters for special method __set__, which has 1 parameter, but should have 3, in class $@. | protocols.py:107:1:107:29 | class MissingMethods | MissingMethods |

0 commit comments

Comments
 (0)