PY-10182 Handle closing parenthesis in tuple literals

This commit is contained in:
Mikhail Golubev
2017-01-11 20:45:19 +03:00
parent 6838043503
commit e5cd4ab83f
6 changed files with 51 additions and 13 deletions

View File

@@ -315,7 +315,10 @@ public class PyBlock implements ASTBlock {
}
}
else if (parentType == PyElementTypes.GENERATOR_EXPRESSION || parentType == PyElementTypes.PARENTHESIZED_EXPRESSION) {
if (childType == PyTokenTypes.RPAR || !hasLineBreaksBeforeInSameParent(child, 1)) {
final boolean insideTuple = parentType == PyElementTypes.PARENTHESIZED_EXPRESSION &&
myNode.getPsi(PyParenthesizedExpression.class).getContainedExpression() instanceof PyTupleExpression;
if ((childType == PyTokenTypes.RPAR && !(insideTuple && settings.HANG_CLOSING_BRACKETS)) ||
!hasLineBreaksBeforeInSameParent(child, 1)) {
childIndent = Indent.getNoneIndent();
}
else {

View File

@@ -0,0 +1,23 @@
xs1 = [
1,
2,
3
]
xs2 = {
1,
2,
3
}
xs3 = {
1: None,
2: None,
3: None,
}
xs4 = (
1,
2,
3
)

View File

@@ -0,0 +1,23 @@
xs1 = [
1,
2,
3
]
xs2 = {
1,
2,
3
}
xs3 = {
1: None,
2: None,
3: None,
}
xs4 = (
1,
2,
3
)

View File

@@ -1,5 +0,0 @@
xs = [
1,
2,
3
]

View File

@@ -1,5 +0,0 @@
xs = [
1,
2,
3
]

View File

@@ -695,11 +695,10 @@ public class PyFormatterTest extends PyTestCase {
}
// PY-10182
public void testHangClosingParenthesisInListLiteral() {
public void testHangClosingBracketsInCollectionLiterals() {
getPythonCodeStyleSettings().HANG_CLOSING_BRACKETS = true;
doTest();
}
public void testVariableAnnotations() {
runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest);