Пример #1
0
def _buildSetUnpacking(provider, elements, source_ref):
    helper_args = []

    for element in elements:

        # TODO: We could be a lot cleverer about the tuples for non-starred
        # arguments, but lets get this to work first.
        if getKind(element) == "Starred":
            helper_args.append(buildNode(provider, element.value, source_ref))
        else:
            helper_args.append(
                ExpressionMakeTuple(elements=(buildNode(provider, element, source_ref),), source_ref=source_ref)
            )

    result = ExpressionFunctionCall(
        function=ExpressionFunctionCreation(
            function_ref=ExpressionFunctionRef(function_body=getSetUnpackingHelper(), source_ref=source_ref),
            code_object=None,
            defaults=(),
            kw_defaults=None,
            annotations=None,
            source_ref=source_ref,
        ),
        values=(ExpressionMakeTuple(helper_args, source_ref),),
        source_ref=source_ref,
    )

    result.setCompatibleSourceReference(helper_args[-1].getCompatibleSourceReference())

    return result
Пример #2
0
def _buildSetUnpacking(provider, elements, source_ref):
    helper_args = []

    for element in elements:

        # We could be a lot cleverer about the tuples for non-starred
        # arguments, but lets get this to work first. And then rely on
        # future optimization to inline the list unpacking helper in a
        # way that has the same effect.
        if getKind(element) == "Starred":
            helper_args.append(buildNode(provider, element.value, source_ref))
        else:
            helper_args.append(
                ExpressionMakeTuple(
                    elements=(buildNode(provider, element, source_ref), ),
                    source_ref=source_ref,
                ))

    result = ExpressionFunctionCall(
        function=ExpressionFunctionCreation(
            function_ref=ExpressionFunctionRef(
                function_body=getSetUnpackingHelper(), source_ref=source_ref),
            defaults=(),
            kw_defaults=None,
            annotations=None,
            source_ref=source_ref,
        ),
        values=(ExpressionMakeTuple(helper_args, source_ref), ),
        source_ref=source_ref,
    )

    result.setCompatibleSourceReference(
        helper_args[-1].getCompatibleSourceReference())

    return result
Пример #3
0
def buildDictionaryUnpacking(provider, node, source_ref):
    helper_args = buildDictionaryUnpackingArgs(provider, node.keys, node.values, source_ref)

    result = ExpressionFunctionCall(
        function   = ExpressionFunctionCreation(
            function_ref = ExpressionFunctionRef(
                function_body = getDictUnpackingHelper(),
                source_ref    = source_ref
            ),
            code_object  = None,
            defaults     = (),
            kw_defaults  = None,
            annotations  = None,
            source_ref   = source_ref
        ),
        values     = (
            ExpressionMakeTuple(
                helper_args,
                source_ref
            ),
        ),
        source_ref = source_ref,
    )

    result.setCompatibleSourceReference(helper_args[-1].getCompatibleSourceReference())

    return result
Пример #4
0
def buildDictionaryUnpacking(provider, node, source_ref):
    helper_args = buildDictionaryUnpackingArgs(provider, node.keys, node.values, source_ref)

    result = ExpressionFunctionCall(
        function   = ExpressionFunctionCreation(
            function_ref = ExpressionFunctionRef(
                function_body = getDictUnpackingHelper(),
                source_ref    = source_ref
            ),
            code_object  = None,
            defaults     = (),
            kw_defaults  = None,
            annotations  = None,
            source_ref   = source_ref
        ),
        values     = (
            ExpressionMakeTuple(
                helper_args,
                source_ref
            ),
        ),
        source_ref = source_ref,
    )

    result.setCompatibleSourceReference(helper_args[-1].getCompatibleSourceReference())

    return result
Пример #5
0
def buildDictionaryUnpacking(provider, node, source_ref):
    helper_args = []

    for key, value in zip(node.keys, node.values):

        # TODO: We could be a lot cleverer about the dictionaries for non-starred
        # arguments, but lets get this to work first.
        if key is None:
            helper_args.append(buildNode(provider, value, source_ref), )
        else:
            helper_args.append(
                ExpressionMakeDict(
                    pairs=(ExpressionKeyValuePair(
                        key=buildNode(provider, key, source_ref),
                        value=buildNode(provider, value, source_ref),
                        source_ref=source_ref), ),
                    source_ref=source_ref,
                    lazy_order=False,
                ))

    result = ExpressionFunctionCall(
        function=ExpressionFunctionCreation(function_ref=ExpressionFunctionRef(
            function_body=getDictUnpackingHelper(), source_ref=source_ref),
                                            defaults=(),
                                            kw_defaults=None,
                                            annotations=None,
                                            source_ref=source_ref),
        values=(ExpressionMakeTuple(helper_args, source_ref), ),
        source_ref=source_ref,
    )

    result.setCompatibleSourceReference(
        helper_args[-1].getCompatibleSourceReference())

    return result
def buildDictionaryUnpacking(provider, node, source_ref):
    helper_args = []

    for key, value in zip(node.keys, node.values):

        # TODO: We could be a lot cleverer about the dictionaries for non-starred
        # arguments, but lets get this to work first.
        if key is None:
            helper_args.append(
                buildNode(provider, value, source_ref),
            )
        else:
            helper_args.append(
                ExpressionMakeDict(
                    pairs      = (
                        ExpressionKeyValuePair(
                            key        = buildNode(provider, key, source_ref),
                            value      = buildNode(provider, value, source_ref),
                            source_ref = source_ref
                        ),
                    ),
                    source_ref = source_ref,
                    lazy_order = False,
                )
            )

    result = ExpressionFunctionCall(
        function   = ExpressionFunctionCreation(
            function_ref = ExpressionFunctionRef(
                function_body = getDictUnpackingHelper(),
                source_ref    = source_ref
            ),
            defaults     = (),
            kw_defaults  = None,
            annotations  = None,
            source_ref   = source_ref
        ),
        values     = (
            ExpressionMakeTuple(
                helper_args,
                source_ref
            ),
        ),
        source_ref = source_ref,
    )

    result.setCompatibleSourceReference(helper_args[-1].getCompatibleSourceReference())

    return result
def _buildSetUnpacking(provider, elements, source_ref):
    helper_args = []

    for element in elements:

        # TODO: We could be a lot cleverer about the tuples for non-starred
        # arguments, but lets get this to work first.
        if getKind(element) == "Starred":
            helper_args.append(
                buildNode(provider, element.value, source_ref),
            )
        else:
            helper_args.append(
                ExpressionMakeTuple(
                    elements   = (
                        buildNode(provider, element, source_ref),
                    ),
                    source_ref = source_ref
                )
            )

    result = ExpressionFunctionCall(
        function   = ExpressionFunctionCreation(
            function_ref = ExpressionFunctionRef(
                function_body = getSetUnpackingHelper(),
                source_ref    = source_ref
            ),
            code_object  = None,
            defaults     = (),
            kw_defaults  = None,
            annotations  = None,
            source_ref   = source_ref
        ),
        values     = (
            ExpressionMakeTuple(
                helper_args,
                source_ref
            ),
        ),
        source_ref = source_ref,
    )

    result.setCompatibleSourceReference(helper_args[-1].getCompatibleSourceReference())

    return result
def buildListUnpacking(provider, elements, source_ref):
    helper_args = []

    for element in elements:

        # We could be a lot cleverer about the tuples for non-starred
        # arguments, but lets get this to work first. And then rely on
        # future optimization to inline the list unpacking helper in a
        # way that has the same effect.
        if getKind(element) == "Starred":
            helper_args.append(buildNode(provider, element.value, source_ref))
        else:
            helper_args.append(
                ExpressionMakeTuple(
                    elements=(buildNode(provider, element, source_ref),),
                    source_ref=source_ref,
                )
            )

    result = ExpressionFunctionCall(
        function=ExpressionFunctionCreation(
            function_ref=ExpressionFunctionRef(
                function_body=getListUnpackingHelper(), source_ref=source_ref
            ),
            defaults=(),
            kw_defaults=None,
            annotations=None,
            source_ref=source_ref,
        ),
        values=(ExpressionMakeTuple(helper_args, source_ref),),
        source_ref=source_ref,
    )

    result.setCompatibleSourceReference(helper_args[-1].getCompatibleSourceReference())

    return result
def _makeCallNode(called, positional_args, keys, values, list_star_arg,
                  dict_star_arg, source_ref):
    # Many variables, but only to cover the many complex call cases.
    # pylint: disable=R0914

    if list_star_arg is None and dict_star_arg is None:
        result = makeExpressionCall(
            called     = called,
            args       = makeSequenceCreationOrConstant(
                sequence_kind = "tuple",
                elements      = positional_args,
                source_ref    = source_ref
            ),
            kw         = makeDictCreationOrConstant(
                keys       = keys,
                values     = values,
                lazy_order = True,
                source_ref = source_ref
            ),
            source_ref = source_ref,
        )

        if values:
            result.setCompatibleSourceReference(
                source_ref = values[-1].getCompatibleSourceReference()
            )
        elif positional_args:
            result.setCompatibleSourceReference(
                source_ref = positional_args[-1].getCompatibleSourceReference()
            )

        return result
    else:
        # Dispatch to complex helper function for each case. These do
        # re-formulation of complex calls according to developer manual.

        key = (
            len(positional_args) > 0,
            len(keys) > 0,
            list_star_arg is not None,
            dict_star_arg is not None
        )

        from .ComplexCallHelperFunctions import (
            getFunctionCallHelperPosKeywordsStarList,
            getFunctionCallHelperPosStarList,
            getFunctionCallHelperKeywordsStarList,
            getFunctionCallHelperStarList,
            getFunctionCallHelperPosKeywordsStarDict,
            getFunctionCallHelperPosStarDict,
            getFunctionCallHelperKeywordsStarDict,
            getFunctionCallHelperStarDict,
            getFunctionCallHelperPosKeywordsStarListStarDict,
            getFunctionCallHelperPosStarListStarDict,
            getFunctionCallHelperKeywordsStarListStarDict,
            getFunctionCallHelperStarListStarDict,
        )

        table = {
            (True,   True,  True, False) :
                getFunctionCallHelperPosKeywordsStarList,
            (True,  False,  True, False) :
                getFunctionCallHelperPosStarList,
            (False,   True,  True, False) :
                getFunctionCallHelperKeywordsStarList,
            (False,  False,  True, False) :
                getFunctionCallHelperStarList,
            (True,   True, False,  True) :
                getFunctionCallHelperPosKeywordsStarDict,
            (True,  False, False,  True) :
                getFunctionCallHelperPosStarDict,
            (False,   True, False,  True) :
                getFunctionCallHelperKeywordsStarDict,
            (False,  False, False,  True) :
                getFunctionCallHelperStarDict,
            (True,   True,  True,  True) :
                getFunctionCallHelperPosKeywordsStarListStarDict,
            (True,  False,  True,  True) :
                getFunctionCallHelperPosStarListStarDict,
            (False,   True,  True,  True) :
                getFunctionCallHelperKeywordsStarListStarDict,
            (False,  False,  True,  True) :
                getFunctionCallHelperStarListStarDict,
        }

        get_helper = table[ key ]

        helper_args = [called]

        if positional_args:
            helper_args.append(
                makeSequenceCreationOrConstant(
                    sequence_kind = "tuple",
                    elements      = positional_args,
                    source_ref    = source_ref
                )
            )

        if python_version >= 350 and list_star_arg is not None:
            helper_args.append(list_star_arg)

        if keys:
            helper_args.append(
                makeDictCreationOrConstant(
                    keys       = keys,
                    values     = values,
                    lazy_order = True,
                    source_ref = source_ref
                )
            )

        if python_version < 350 and list_star_arg is not None:
            helper_args.append(list_star_arg)

        if dict_star_arg is not None:
            helper_args.append(dict_star_arg)

        result = ExpressionFunctionCall(
            function   = ExpressionFunctionCreation(
                function_ref = ExpressionFunctionRef(
                    function_body = get_helper(),
                    source_ref    = source_ref
                ),
                defaults     = (),
                kw_defaults  = None,
                annotations  = None,
                source_ref   = source_ref
            ),
            values     = helper_args,
            source_ref = source_ref,
        )

        result.setCompatibleSourceReference(
            source_ref = helper_args[-1].getCompatibleSourceReference()
        )

        return result
Пример #10
0
def _makeCallNode(called, positional_args, keys, values, list_star_arg,
                  dict_star_arg, source_ref):
    # Many variables, but only to cover the many complex call cases.

    if list_star_arg is None and dict_star_arg is None:
        result = makeExpressionCall(
            called=called,
            args=makeSequenceCreationOrConstant(sequence_kind="tuple",
                                                elements=positional_args,
                                                source_ref=source_ref),
            kw=makeDictCreationOrConstant(keys=keys,
                                          values=values,
                                          source_ref=source_ref),
            source_ref=source_ref,
        )

        # Bug compatible line numbers before Python 3.8
        if python_version < 380:
            if values:
                result.setCompatibleSourceReference(
                    source_ref=values[-1].getCompatibleSourceReference())
            elif positional_args:
                result.setCompatibleSourceReference(
                    source_ref=positional_args[-1].
                    getCompatibleSourceReference())

        return result
    else:
        # Dispatch to complex helper function for each case. These do
        # re-formulation of complex calls according to developer manual.

        key = (
            bool(positional_args),
            bool(keys),
            list_star_arg is not None,
            dict_star_arg is not None,
        )

        table = {
            (True, True, True, False):
            getFunctionCallHelperPosKeywordsStarList,
            (True, False, True, False): getFunctionCallHelperPosStarList,
            (False, True, True, False): getFunctionCallHelperKeywordsStarList,
            (False, False, True, False): getFunctionCallHelperStarList,
            (True, True, False, True):
            getFunctionCallHelperPosKeywordsStarDict,
            (True, False, False, True): getFunctionCallHelperPosStarDict,
            (False, True, False, True): getFunctionCallHelperKeywordsStarDict,
            (False, False, False, True): getFunctionCallHelperStarDict,
            (True, True, True, True):
            getFunctionCallHelperPosKeywordsStarListStarDict,
            (True, False, True, True):
            getFunctionCallHelperPosStarListStarDict,
            (False, True, True, True):
            getFunctionCallHelperKeywordsStarListStarDict,
            (False, False, True, True): getFunctionCallHelperStarListStarDict,
        }

        get_helper = table[key]

        helper_args = [called]

        if positional_args:
            helper_args.append(
                makeSequenceCreationOrConstant(
                    sequence_kind="tuple",
                    elements=positional_args,
                    source_ref=source_ref,
                ))

        # Order of evaluation changed in Python3.5.
        if python_version >= 350 and list_star_arg is not None:
            helper_args.append(list_star_arg)

        if keys:
            helper_args.append(
                makeDictCreationOrConstant(keys=keys,
                                           values=values,
                                           source_ref=source_ref))

        # Order of evaluation changed in Python3.5.
        if python_version < 350 and list_star_arg is not None:
            helper_args.append(list_star_arg)

        if dict_star_arg is not None:
            helper_args.append(dict_star_arg)

        result = ExpressionFunctionCall(
            function=ExpressionFunctionCreation(
                function_ref=ExpressionFunctionRef(function_body=get_helper(),
                                                   source_ref=source_ref),
                defaults=(),
                kw_defaults=None,
                annotations=None,
                source_ref=source_ref,
            ),
            values=helper_args,
            source_ref=source_ref,
        )

        # Bug compatible line numbers before Python 3.8
        if python_version < 380:
            result.setCompatibleSourceReference(
                source_ref=helper_args[-1].getCompatibleSourceReference())

        return result