diff --git a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java index 86cddae4ffe9..06e347dee765 100644 --- a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java +++ b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java @@ -177,6 +177,17 @@ public class ScopeImpl implements Scope { super.visitPyNonlocalStatement(node); } + @Override + public void visitPyFunction(PyFunction node) { + for (PyParameter parameter : node.getParameterList().getParameters()) { + final PyExpression defaultValue = parameter.getDefaultValue(); + if (defaultValue != null) { + defaultValue.accept(this); + } + } + super.visitPyFunction(node); + } + @Override public void visitPyElement(PyElement node) { if (node instanceof PsiNamedElement && !(node instanceof PyKeywordArgument)) { diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/comprehensionInParameterValue.py b/python/testData/inspections/PyUnresolvedReferencesInspection/comprehensionInParameterValue.py new file mode 100644 index 000000000000..400b5503f6b5 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/comprehensionInParameterValue.py @@ -0,0 +1,2 @@ +def f(x=[i for i in [1, 2, 3]]): # i is resolved in file scope to i + return x diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index 0698506047b6..bf35293c907e 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -221,6 +221,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase { }); } + // PY-7516 + public void testComprehensionInParameterValue() { + doTest(); + } + private void doTest() { myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py"); myFixture.enableInspections(PyUnresolvedReferencesInspection.class);