diff --git a/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java b/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java index d84003b9cd50..4c79f0f6f04b 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyUnboundLocalVariableInspection.java @@ -81,7 +81,8 @@ public class PyUnboundLocalVariableInspection extends PyInspection { continue; } } - if (PyAssignmentStatementNavigator.getStatementByTarget(element) != null) { + if (PyAssignmentStatementNavigator.getStatementByTarget(element) != null || + PyForStatementNavigator.getPyForStatementByIterable(element) != null) { resolves2LocalVariable = true; resolve2Scope = PsiTreeUtil.isAncestor(owner, element, false); break; diff --git a/python/testData/inspections/PyUnboundLocalVariableInspection/expected.xml b/python/testData/inspections/PyUnboundLocalVariableInspection/expected.xml index 0d31ce834b19..d4d8c9ea8771 100644 --- a/python/testData/inspections/PyUnboundLocalVariableInspection/expected.xml +++ b/python/testData/inspections/PyUnboundLocalVariableInspection/expected.xml @@ -10,4 +10,9 @@ 14 "Name 'b' can be not defined" + + test.py + 51 + "Name 'i' can be not defined" + \ No newline at end of file