Beispiel #1
0
def conditionalExpr(ctx, style, condition, expr, elseExpr):
    conditionalSpacing = style.get(PythonEditorStyle.conditionalSpacing)

    return LineBreakCostSpan([
        expr,
        Whitespace('  ', conditionalSpacing), _lineBreak,
        _keyword('if'), _space, condition,
        Whitespace('  ', conditionalSpacing), _lineBreak,
        _keyword('else'), _space, elseExpr
    ]).present(ctx, style)
Beispiel #2
0
def dictComp(ctx, style, resultExpr, comprehensionItems):
    comprehensionSpacing = style.get(PythonEditorStyle.comprehensionSpacing)
    itemViewsSpaced = []
    if len(comprehensionItems) > 0:
        for x in comprehensionItems[:-1]:
            itemViewsSpaced.append(x)
            itemViewsSpaced.append(Whitespace(' ', comprehensionSpacing))
            itemViewsSpaced.append(_lineBreak)
        itemViewsSpaced.append(comprehensionItems[-1])
    return LineBreakCostSpan(
        [_openBrace, resultExpr,
         Whitespace(' ', comprehensionSpacing)] + itemViewsSpaced +
        [_closeBrace]).present(ctx, style)
Beispiel #3
0
def call(target, args, bArgsTrailingSeparator):
    argElements = []
    if len(args) > 0:
        argElements.append(_space)
        argSpanElements = []
        for a in args[:-1]:
            argSpanElements.append(a)
            argSpanElements.append(_comma)
            argSpanElements.append(_space)
            argSpanElements.append(_lineBreak)
        argSpanElements.append(args[-1])
        if bArgsTrailingSeparator:
            argSpanElements.append(_comma)
        argElements.append(ParagraphIndentMatchSpan(argSpanElements))
        argElements.append(_space)
    return LineBreakCostSpan([target, _openParen] + argElements +
                             [_closeParen])
Beispiel #4
0
def lambdaExpr(params, bParamsTrailingSeparator, expr):
    elements = []
    if len(params) > 0:
        for p in params[:-1]:
            elements.append(p)
            elements.append(_comma)
            elements.append(_space)
            elements.append(_lineBreak)
        elements.append(params[-1])
        if bParamsTrailingSeparator:
            elements.append(_comma)
            elements.append(_space)
            elements.append(_lineBreak)

    return LineBreakCostSpan([
        _keyword('lambda'), _space,
        ParagraphIndentMatchSpan(elements), _colon, _space, _lineBreak, expr
    ])
Beispiel #5
0
def compare(x, cmpOps):
    return LineBreakCostSpan([x] + cmpOps)
Beispiel #6
0
def spanBinOp(x, y, op):
    opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                          Text(op))
    return LineBreakCostSpan([x, Text(' '), opView, Text(' '), _lineBreak, y])
Beispiel #7
0
def spanPrefixOp(x, op):
    opView = ApplyStyleSheetFromAttribute(PythonEditorStyle.operatorStyle,
                                          Text(op))
    return LineBreakCostSpan([opView, x])