PY-21823 Align bound and stride expressions inside slices

This commit is contained in:
Mikhail Golubev
2017-09-25 15:36:23 +03:00
parent 2a98affca7
commit eb600f7046
4 changed files with 30 additions and 1 deletions
@@ -327,6 +327,10 @@ public class PyBlock implements ASTBlock {
childIndent = Indent.getNoneIndent();
}
}
// Note that colons are aligned together with bounds and stride
else if (myNode.getElementType() == PyElementTypes.SLICE_ITEM) {
childAlignment = getChildAlignment();
}
else if (parentType == PyElementTypes.GENERATOR_EXPRESSION || parentType == PyElementTypes.PARENTHESIZED_EXPRESSION) {
final boolean tupleOrGenerator = parentType == PyElementTypes.GENERATOR_EXPRESSION ||
myNode.getPsi(PyParenthesizedExpression.class).getContainedExpression() instanceof PyTupleExpression;
@@ -934,7 +938,7 @@ public class PyBlock implements ASTBlock {
@Nullable
private Alignment getChildAlignment() {
if (ourListElementTypes.contains(myNode.getElementType())) {
if (ourListElementTypes.contains(myNode.getElementType()) || myNode.getElementType() == PyElementTypes.SLICE_ITEM) {
if (isInControlStatement()) {
return null;
}
@@ -0,0 +1,10 @@
xs1 = ys[42:
5:
-1]
xs2 = ys[:
2:
3]
xs3 = ys[::
3]
@@ -0,0 +1,10 @@
xs1 = ys[42:
5:
-1]
xs2 = ys[:
2:
3]
xs3 = ys[::
3]
@@ -847,6 +847,11 @@ public class PyFormatterTest extends PyTestCase {
doTest();
}
// PY-21823
public void testSliceAlignment() {
doTest();
}
public void testVariableAnnotations() {
runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);
}