PY-32472, PY-36767: Ignore Django CBV methods' params that are required by signature + fix NPE

request, *args and **kwargs should not be marked as "unused" in CBV.

"request" is part of signature and args are used to pass "as-is" to the dispatch

GitOrigin-RevId: c83d7301252e7982254a7aadbe33ed07fa7accec
This commit is contained in:
Ilya.Kazakevich
2019-08-24 03:01:17 +03:00
committed by intellij-monorepo-bot
parent af20666b3b
commit 976feaa4b7
@@ -0,0 +1,22 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.extensions.python
import com.jetbrains.python.FunctionParameter
import com.jetbrains.python.psi.PyFunction
import com.jetbrains.python.psi.PyParameter
fun PyFunction.getParameter(paramToSearch: FunctionParameter): PyParameter? {
val parameterList = this.parameterList
val position = paramToSearch.position
val name = paramToSearch.name
if (name != null) {
parameterList.findParameterByName(name)?.let {
return it
}
}
if (position != FunctionParameter.POSITION_NOT_SUPPORTED) {
val hasSelf = containingClass != null
return parameterList.parameters.getOrNull(if (hasSelf) position + 1 else position)
}
return null
}