Python: Modernise py/unused-parameter

This commit is contained in:
Rasmus Wriedt Larsen
2019-12-17 16:23:33 +01:00
parent 15bc4cd090
commit 34f9135492

View File

@@ -13,19 +13,19 @@ import python
import Definition
predicate unused_parameter(FunctionObject f, LocalVariable v) {
predicate unused_parameter(FunctionValue f, LocalVariable v) {
v.isParameter() and
v.getScope() = f.getFunction() and
v.getScope() = f.getScope() and
not name_acceptable_for_unused_variable(v) and
not exists(NameNode u | u.uses(v)) and
not exists(Name inner, LocalVariable iv | inner.uses(iv) and iv.getId() = v.getId() and inner.getScope().getScope() = v.getScope())
}
predicate is_abstract(FunctionObject func) {
((Name)func.getFunction().getADecorator()).getId().matches("%abstract%")
predicate is_abstract(FunctionValue func) {
func.getScope().getADecorator().(Name).getId().matches("%abstract%")
}
from PyFunctionObject f, LocalVariable v
from PythonFunctionValue f, LocalVariable v
where v.getId() != "self" and unused_parameter(f, v) and not f.isOverridingMethod() and not f.isOverriddenMethod() and
not is_abstract(f)
select f, "The parameter '" + v.getId() + "' is never used."