mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
PY-20832 Fixed: __iter__ is not inferred from for-statement
Update PyNamedParameterImpl.collectUsedAttributes to honour for-statements
This commit is contained in:
@@ -361,6 +361,18 @@ public class PyNamedParameterImpl extends PyBaseElementImpl<PyNamedParameterStub
|
||||
|
||||
super.visitPyCallExpression(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyForStatement(PyForStatement node) {
|
||||
Optional
|
||||
.of(node.getForPart())
|
||||
.map(PyForPart::getSource)
|
||||
.map(PyExpression::getReference)
|
||||
.filter(reference -> reference.isReferenceTo(PyNamedParameterImpl.this))
|
||||
.ifPresent(reference -> result.add(PyNames.ITER));
|
||||
|
||||
super.visitPyForStatement(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -19,16 +19,15 @@ def expand(values1, values2):
|
||||
<weak_warning descr="Assignment can be replaced with augmented assignment">values1 = values1 + values2</weak_warning>
|
||||
|
||||
|
||||
#def expand(values1, values2):
|
||||
# for a in values1:
|
||||
# print(a)
|
||||
#
|
||||
# for b in values2:
|
||||
# print(b)
|
||||
#
|
||||
# values1 = values2 + values1
|
||||
# values1 = values1 + values2
|
||||
# inspection should suggest replacement only for the second assignment
|
||||
def expand(values1, values2):
|
||||
for a in values1:
|
||||
print(a)
|
||||
|
||||
for b in values2:
|
||||
print(b)
|
||||
|
||||
values1 = values2 + values1
|
||||
<weak_warning descr="Assignment can be replaced with augmented assignment">values1 = values1 + values2</weak_warning>
|
||||
|
||||
|
||||
def expand(values1, values2):
|
||||
|
||||
@@ -1145,6 +1145,15 @@ public class PyTypeTest extends PyTestCase {
|
||||
"expr = f\n");
|
||||
}
|
||||
|
||||
// PY-20832
|
||||
public void testStructuralTypeWithDunderIter() {
|
||||
doTest("{__iter__}",
|
||||
"def expand(values1):\n" +
|
||||
" for a in values1:\n" +
|
||||
" print(a)\n" +
|
||||
" expr = values1\n");
|
||||
}
|
||||
|
||||
// PY-20833
|
||||
public void testStructuralTypeWithDunderLen() {
|
||||
doTest("{__len__}",
|
||||
|
||||
Reference in New Issue
Block a user