mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-2648 Dictionary creation intention breaks code when a value is a tuple
This commit is contained in:
@@ -148,7 +148,14 @@ public class PyAssignmentStatementImpl extends PyElementImpl implements PyAssign
|
||||
|
||||
PySequenceExpression rhs_tuple = null;
|
||||
PyExpression rhs_one = null;
|
||||
if (rhs instanceof PySequenceExpression) rhs_tuple = (PySequenceExpression)rhs;
|
||||
if (rhs instanceof PyParenthesizedExpression) {
|
||||
PyExpression exp = ((PyParenthesizedExpression)rhs).getContainedExpression();
|
||||
if (exp instanceof PyTupleExpression)
|
||||
rhs_tuple = (PySequenceExpression)exp;
|
||||
else
|
||||
rhs_one = rhs;
|
||||
}
|
||||
else if (rhs instanceof PySequenceExpression) rhs_tuple = (PySequenceExpression)rhs;
|
||||
else if (rhs != null) rhs_one = rhs;
|
||||
//
|
||||
if (lhs_one != null) { // single LHS, single RHS (direct mapping) or multiple RHS (packing)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<dst1>a, <dst2>b = (<src1>1, <src2>2)
|
||||
@@ -112,6 +112,30 @@ public class PyAssignmentMappingTest extends LightMarkedTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testParenthesizedTuple() throws Exception { //PY-2648
|
||||
Map<String, PsiElement> marks = loadTest();
|
||||
final int PAIR_NUM = 2;
|
||||
assertEquals(PAIR_NUM*2, marks.size());
|
||||
PsiElement[] srcs = new PsiElement[PAIR_NUM];
|
||||
PsiElement[] dsts = new PsiElement[PAIR_NUM];
|
||||
for (int i=0; i<PAIR_NUM; i+=1) {
|
||||
PsiElement dst = marks.get("<dst" + String.valueOf(i + 1) + ">").getParent(); // ident -> target expr
|
||||
assertTrue(dst instanceof PyTargetExpression);
|
||||
dsts[i] = dst;
|
||||
PsiElement src = marks.get("<src" + String.valueOf(i + 1) +">").getParent(); // ident -> target expr
|
||||
assertTrue(src instanceof PyExpression);
|
||||
srcs[i] = src;
|
||||
}
|
||||
PyAssignmentStatement stmt = (PyAssignmentStatement)srcs[0].getParent().getParent().getParent(); // tuple expr -> assignment
|
||||
List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
|
||||
assertEquals(PAIR_NUM, mapping.size());
|
||||
for (int i=0; i<PAIR_NUM; i+=1) {
|
||||
Pair<PyExpression, PyExpression> pair = mapping.get(i);
|
||||
assertEquals(dsts[i], pair.getFirst());
|
||||
assertEquals(srcs[i], pair.getSecond());
|
||||
}
|
||||
}
|
||||
|
||||
public void testTuplePack() throws Exception {
|
||||
Map<String, PsiElement> marks = loadTest();
|
||||
final int SRC_NUM = 2;
|
||||
|
||||
Reference in New Issue
Block a user