Fix alignment in list comprehension in dict (PY-10076).

This commit is contained in:
Dmitry Trofimov
2014-02-04 13:59:25 +04:00
parent e8fd0a0488
commit 62476fa88f
4 changed files with 38 additions and 0 deletions
@@ -141,6 +141,26 @@ public class PyBlock implements ASTBlock {
Wrap wrap = null;
Indent childIndent = Indent.getNoneIndent();
Alignment childAlignment = null;
//First we are going to set-up possible alignment to parents
PyBlock p = !breaksAlignment(parentType) ? myParent : null;
while (p != null) {
ASTNode pNode = p.getNode();
if (ourListElementTypes.contains(pNode.getElementType())) {
if (needListAlignment(child) && !isEmptyList(_node.getPsi()) && !isInControlStatement()) {
childAlignment = p.getChildAlignment();
break;
}
}
if (!breaksAlignment(pNode.getElementType())) {
p = p.myParent;
}
else {
break;
}
}
if (childType == PyElementTypes.STATEMENT_LIST) {
if (hasLineBreaksBefore(child, 1) || needLineBreakInStatement()) {
childIndent = Indent.getNormalIndent();
@@ -309,6 +329,10 @@ public class PyBlock implements ASTBlock {
return new PyBlock(this, child, childAlignment, childIndent, wrap, myContext);
}
private static boolean breaksAlignment(IElementType type) {
return type != PyElementTypes.BINARY_EXPRESSION;
}
private static Alignment getAlignmentOfChild(PyBlock b, int childNum) {
if (b.getSubBlocks().size() > childNum) {
ChildAttributes attributes = b.getChildAttributes(childNum);
@@ -0,0 +1,5 @@
def foo():
return {field.key: field for key, field in inspect.getmembers(instance)
if isinstance(field, QueryableAttribute)
and isinstance(field.property, ColumnProperty)
or field.foreign_keys}
@@ -0,0 +1,5 @@
def foo():
return {field.key: field for key, field in inspect.getmembers(instance)
if isinstance(field, QueryableAttribute)
and isinstance(field.property, ColumnProperty)
or field.foreign_keys}
@@ -394,6 +394,10 @@ public class PyFormatterTest extends PyTestCase {
doTest();
}
public void testAlignListComprehensionInDict() { //PY-10076
doTest();
}
private void doTest() {
doTest(false);
}