From 976feaa4b71620823cc312ceba309a3e02097bf1 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Sat, 24 Aug 2019 02:27:41 +0300 Subject: [PATCH] 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 --- .../extensions/python/PyFunctionExt.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 python/src/com/jetbrains/extensions/python/PyFunctionExt.kt diff --git a/python/src/com/jetbrains/extensions/python/PyFunctionExt.kt b/python/src/com/jetbrains/extensions/python/PyFunctionExt.kt new file mode 100644 index 000000000000..cfdd54838139 --- /dev/null +++ b/python/src/com/jetbrains/extensions/python/PyFunctionExt.kt @@ -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 +}