Пример #1
0
        # Apply our decision.
        if shouldUseConstructor:
            # Call ctor manually to avoid having promote() called on the output.
            ComputedObject.__init__(self, ctor,
                                    ctor.promoteArgs(ctor.nameArgs(args)))
        else:
            # Just cast and hope for the best.
            if not onlyOneArg:
                # We don't know what to do with multiple args.
                raise EEException('Too many arguments for ee.%s(): %s' %
                                  (name, args))
            elif firstArgIsPrimitive:
                # Can't cast a primitive.
                raise EEException(
                    'Invalid argument for ee.%s(): %s.  Must be a ComputedObject.'
                    % (name, args))
            else:
                result = args[0]
            ComputedObject.__init__(self, result.func, result.args,
                                    result.varName)

    properties = {'__init__': init, 'name': lambda self: name}
    new_class = type(str(name), (ComputedObject, ), properties)
    ApiFunction.importApi(new_class, name, name)
    return new_class


# Set up type promotion rules as soon the package is loaded.
Function._registerPromoter(_Promote)  # pylint: disable=protected-access
Пример #2
0
                    # Can't cast a primitive.
                    shouldUseConstructor = True
                elif args[0].func != ctor:
                    # We haven't already called the constructor on this object.
                    shouldUseConstructor = True

        # Apply our decision.
        if shouldUseConstructor:
            # Call ctor manually to avoid having promote() called on the output.
            ComputedObject.__init__(self, ctor, ctor.promoteArgs(ctor.nameArgs(args)))
        else:
            # Just cast and hope for the best.
            if not onlyOneArg:
                # We don't know what to do with multiple args.
                raise EEException("Too many arguments for ee.%s(): %s" % (name, args))
            elif firstArgIsPrimitive:
                # Can't cast a primitive.
                raise EEException("Invalid argument for ee.%s(): %s.  Must be a ComputedObject." % (name, args))
            else:
                result = args[0]
            ComputedObject.__init__(self, result.func, result.args, result.varName)

    properties = {"__init__": init, "name": lambda self: name}
    new_class = type(str(name), (ComputedObject,), properties)
    ApiFunction.importApi(new_class, name, name)
    return new_class


# Set up type promotion rules as soon the package is loaded.
Function._registerPromoter(_Promote)  # pylint: disable=protected-access