mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix alignment in list comprehension in dict (PY-10076).
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user