mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-6283 Introscpection- "This dictionary creation could be rewritten as a dictionary literal" produces invalid code
This commit is contained in:
@@ -62,7 +62,18 @@ public class DictCreationQuickFix implements LocalQuickFix {
|
||||
final PySubscriptionExpression subscription = (PySubscriptionExpression)targetToValue.first;
|
||||
final PyExpression indexExpression = subscription.getIndexExpression();
|
||||
assert indexExpression != null;
|
||||
statements.add(indexExpression.getText() + ": " + targetToValue.second.getText());
|
||||
final String indexText;
|
||||
if (indexExpression instanceof PyTupleExpression)
|
||||
indexText = "("+indexExpression.getText()+")";
|
||||
else
|
||||
indexText = indexExpression.getText();
|
||||
|
||||
final String valueText;
|
||||
if (targetToValue.second instanceof PyTupleExpression)
|
||||
valueText = "("+targetToValue.second.getText()+")";
|
||||
else
|
||||
valueText = targetToValue.second.getText();
|
||||
statements.add(indexText + ": " + valueText);
|
||||
statement.delete();
|
||||
}
|
||||
statement = nextStatement;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<caret><warning descr="This dictionary creation could be rewritten as a dictionary literal">dict = {}</warning>
|
||||
dict[1,2] = 3,4
|
||||
@@ -0,0 +1 @@
|
||||
dict = {(1, 2): (3, 4)}
|
||||
@@ -123,6 +123,10 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
doInspectionTest("DictCreation.py", PyDictCreationInspection.class, PyBundle.message("QFIX.dict.creation"), true, true);
|
||||
}
|
||||
|
||||
public void testDictCreationTuple() { //PY-6283
|
||||
doInspectionTest("DictCreationTuple.py", PyDictCreationInspection.class, PyBundle.message("QFIX.dict.creation"), true, true);
|
||||
}
|
||||
|
||||
public void testTransformClassicClass() {
|
||||
doInspectionTest("TransformClassicClass.py", PyClassicStyleClassInspection.class,
|
||||
PyBundle.message("QFIX.classic.class.transform"), true, true);
|
||||
|
||||
Reference in New Issue
Block a user