def wrapSuperBuiltin(type_arg, object_arg, source_ref):
        if type_arg is None and python_version >= 300:
            type_arg = ExpressionVariableRef(variable_name="__class__",
                                             source_ref=source_ref)

            # Ought to be already closure taken.
            type_arg.setVariable(
                provider.getVariableForReference(variable_name="__class__"))

            # If we already have this as a local variable, then use that
            # instead.
            type_arg_owner = type_arg.getVariable().getOwner()
            if type_arg_owner is provider or \
            not (type_arg_owner.isExpressionFunctionBody() or \
                 type_arg_owner.isExpressionClassBody()):
                type_arg = None

            if type_arg is None:
                return makeRaiseExceptionReplacementExpression(
                    expression=node,
                    exception_type="SystemError"
                    if python_version < 331 else "RuntimeError",
                    exception_value="super(): __class__ cell not found",
                )

            if object_arg is None:
                if provider.isExpressionGeneratorObjectBody() or \
                   provider.isExpressionCoroutineObjectBody() or \
                   provider.isExpressionAsyncgenObjectBody():
                    parameter_provider = provider.getParentVariableProvider()
                else:
                    parameter_provider = provider

                if parameter_provider.getParameters().getArgumentCount() > 0:
                    par1_name = parameter_provider.getParameters(
                    ).getArgumentNames()[0]

                    object_arg = ExpressionVariableRef(variable_name=par1_name,
                                                       source_ref=source_ref)

                    object_arg.setVariable(
                        provider.getVariableForReference(
                            variable_name=par1_name))

                    if not object_arg.getVariable().isParameterVariable():
                        return makeRaiseExceptionReplacementExpression(
                            expression=node,
                            exception_type="SystemError"
                            if python_version < 330 else "RuntimeError",
                            exception_value="super(): __class__ cell not found",
                        )
                else:
                    return makeRaiseExceptionReplacementExpression(
                        expression=node,
                        exception_type="RuntimeError",
                        exception_value="super(): no arguments")

        return ExpressionBuiltinSuper(super_type=type_arg,
                                      super_object=object_arg,
                                      source_ref=source_ref)
Esempio n. 2
0
    def wrapSuperBuiltin(type, object, source_ref):
        if type is None and python_version >= 300:
            provider = node.getParentVariableProvider()

            type = ExpressionVariableRef(variable_name="__class__",
                                         source_ref=source_ref)

            # Ought to be already closure taken.
            type.setVariable(
                provider.getVariableForReference(variable_name="__class__"))

            from nuitka.nodes.NodeMakingHelpers import makeRaiseExceptionReplacementExpression

            if not type.getVariable().isClosureReference():
                return makeRaiseExceptionReplacementExpression(
                    expression=node,
                    exception_type="SystemError"
                    if python_version < 331 else "RuntimeError",
                    exception_value="super(): __class__ cell not found",
                )

            if object is None and provider.getParameters().getArgumentCount(
            ) > 0:
                par1_name = provider.getParameters().getArgumentNames()[0]
                # TODO: Nested first argument would kill us here, need a test
                # for that.

                object = ExpressionVariableRef(variable_name=par1_name,
                                               source_ref=source_ref)

                object.setVariable(
                    node.getParentVariableProvider().getVariableForReference(
                        variable_name=par1_name))

                if not object.getVariable().isParameterVariable():
                    return makeRaiseExceptionReplacementExpression(
                        expression=node,
                        exception_type="SystemError"
                        if python_version < 330 else "RuntimeError",
                        exception_value="super(): __class__ cell not found",
                    )

        return ExpressionBuiltinSuper(super_type=type,
                                      super_object=object,
                                      source_ref=source_ref)
    def wrapSuperBuiltin(type_arg, object_arg, source_ref):
        if type_arg is None and python_version >= 300:
            if provider.isCompiledPythonModule():
                return makeRaiseExceptionReplacementExpression(
                    expression=node,
                    exception_type="RuntimeError",
                    exception_value="super(): no arguments",
                )

            class_variable = provider.getVariableForReference(
                variable_name="__class__")

            provider.trace_collection.getVariableCurrentTrace(
                class_variable).addUsage()

            type_arg = ExpressionVariableRef(
                # Ought to be already closure taken due to "super" flag in
                # tree building.
                variable=class_variable,
                source_ref=source_ref,
            )

            # If we already have this as a local variable, then use that
            # instead.
            type_arg_owner = type_arg.getVariable().getOwner()
            if type_arg_owner is provider or not (
                    type_arg_owner.isExpressionFunctionBody()
                    or type_arg_owner.isExpressionClassBody()):
                type_arg = None

            if type_arg is None:
                return makeRaiseExceptionReplacementExpression(
                    expression=node,
                    exception_type="SystemError"
                    if python_version < 331 else "RuntimeError",
                    exception_value="super(): __class__ cell not found",
                )

            if object_arg is None:
                if (provider.isExpressionGeneratorObjectBody()
                        or provider.isExpressionCoroutineObjectBody()
                        or provider.isExpressionAsyncgenObjectBody()):
                    parameter_provider = provider.getParentVariableProvider()
                else:
                    parameter_provider = provider

                if parameter_provider.getParameters().getArgumentCount() > 0:
                    par1_name = parameter_provider.getParameters(
                    ).getArgumentNames()[0]

                    object_variable = provider.getVariableForReference(
                        variable_name=par1_name)

                    provider.trace_collection.getVariableCurrentTrace(
                        object_variable).addUsage()

                    object_arg = ExpressionVariableRef(
                        variable=object_variable, source_ref=source_ref)

                    if not object_arg.getVariable().isParameterVariable():
                        return makeRaiseExceptionReplacementExpression(
                            expression=node,
                            exception_type="SystemError"
                            if python_version < 300 else "RuntimeError",
                            exception_value="super(): __class__ cell not found",
                        )
                else:
                    return makeRaiseExceptionReplacementExpression(
                        expression=node,
                        exception_type="RuntimeError",
                        exception_value="super(): no arguments",
                    )

        return ExpressionBuiltinSuper(super_type=type_arg,
                                      super_object=object_arg,
                                      source_ref=source_ref)
Esempio n. 4
0
    def wrapSuperBuiltin(type, object, source_ref):
        if type is None and python_version >= 300:
            provider = node.getParentVariableProvider()

            if python_version < 340 or True: # TODO: Temporarily reverted:
                type = ExpressionVariableRef(
                    variable_name = "__class__",
                    source_ref    = source_ref
                )

                # Ought to be already closure taken.
                type.setVariable(
                    provider.getVariableForClosure(
                        variable_name = "__class__"
                    )
                )

                # If we already have this as a local variable, then use that
                # instead.
                if not type.getVariable().isClosureReference():
                    type = None
                else:
                    from nuitka.VariableRegistry import addVariableUsage
                    addVariableUsage(type.getVariable(), provider)
            else:
                parent_provider = provider.getParentVariableProvider()

                class_var = parent_provider.getTempVariable(
                    temp_scope = None,
                    name       = "__class__"
                )

                type = ExpressionTempVariableRef(
                    variable      = class_var.makeReference(parent_provider).makeReference(provider),
                    source_ref    = source_ref
                )

                from nuitka.VariableRegistry import addVariableUsage
                addVariableUsage(type.getVariable(), provider)

            from nuitka.nodes.NodeMakingHelpers import \
                makeRaiseExceptionReplacementExpression

            if type is None:
                return makeRaiseExceptionReplacementExpression(
                    expression      = node,
                    exception_type  = "SystemError"
                                        if python_version < 331 else
                                      "RuntimeError",
                    exception_value = "super(): __class__ cell not found",
                )

            if object is None:
                if provider.getParameters().getArgumentCount() > 0:
                    par1_name = provider.getParameters().getArgumentNames()[0]
                    # TODO: Nested first argument would kill us here, need a
                    # test for that.

                    object = ExpressionVariableRef(
                        variable_name = par1_name,
                        source_ref    = source_ref
                    )

                    object.setVariable(
                        provider.getVariableForReference(
                            variable_name = par1_name
                        )
                    )

                    if not object.getVariable().isParameterVariable():
                        return makeRaiseExceptionReplacementExpression(
                            expression      = node,
                            exception_type  = "SystemError"
                                                if python_version < 330 else
                                              "RuntimeError",
                            exception_value = "super(): __class__ cell not found",
                        )
                else:
                    return makeRaiseExceptionReplacementExpression(
                        expression      = node,
                        exception_type  = "RuntimeError",
                        exception_value = "super(): no arguments"
                    )

        return ExpressionBuiltinSuper(
            super_type   = type,
            super_object = object,
            source_ref   = source_ref
        )