diff --git a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/ScopeUtil.java b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/ScopeUtil.java index 6534e45ba270..11b36602f708 100644 --- a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/ScopeUtil.java +++ b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/ScopeUtil.java @@ -57,10 +57,12 @@ public class ScopeUtil { @Nullable public static ScopeOwner getResolveScopeOwner(PsiElement element) { - // References in default values of parameters are defined somewhere in outer scopes, as well as references in decorators and - // superclasses - if (PsiTreeUtil.getParentOfType(element, PyParameter.class, PyDecorator.class) != null) { - element = getScopeOwner(element); + // References in default values of parameters are defined somewhere in outer scopes, as well as references in decorators (if they are + // not inside a lambda, see PY-6083) and superclasses + final ScopeOwner initialScopeOwner = getScopeOwner(element); + if (!(initialScopeOwner instanceof PyLambdaExpression && PsiTreeUtil.getParentOfType(element, PyDecorator.class) != null) && + PsiTreeUtil.getParentOfType(element, PyParameter.class, PyDecorator.class) != null) { + element = initialScopeOwner; } final PyClass containingClass = PsiTreeUtil.getParentOfType(element, PyClass.class); if (containingClass != null && element != null && diff --git a/python/testData/resolve/LambdaParameterInDecorator.py b/python/testData/resolve/LambdaParameterInDecorator.py new file mode 100644 index 000000000000..8efbb46f864d --- /dev/null +++ b/python/testData/resolve/LambdaParameterInDecorator.py @@ -0,0 +1,6 @@ +def f(y): + return y + +@f(lambda xx: xx) +def g(): + pass diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index 4e2162fc1502..0331ccfeb0ac 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -457,4 +457,9 @@ public class PyResolveTest extends PyResolveTestCase { final PyFunction function = assertResolvesTo(PyFunction.class, "getStore"); assertEquals("PluginMetaclass", function.getContainingClass().getName()); } + + // PY-6083 + public void testLambdaParameterInDecorator() { + assertResolvesTo(PyNamedParameter.class, "xx"); + } }