Exemple #1
0
def get_overloads(func):
    res = []
	
    if type(func) == type(list.append):
        func = PythonOps.GetBuiltinMethodDescriptorTemplate(func)

    for target in func.Targets:
		args = list(target.GetParameters())
		if args and args[0].ParameterType.FullName == 'IronPython.Runtime.CodeContext':
			del args[0]
		if args and args[0].ParameterType.IsSubclassOf(SiteLocalStorage):
			del args[0]

		try:
			arg_info = [get_parameter_info(arg) for arg in args]
			if not target.IsStatic:
				arg_info = [{'type' : type_to_name(target.DeclaringType), 'name': 'self'}] + arg_info

			res.append(
				{'args' :  arg_info,
				 'ret_type' : type_to_name(target.ReturnType), }
			)
		except NonPythonTypeException:
			pass

    return tuple(res)
    def collect_signatures(self, val):
        doc = val.__doc__
        type_obj = None
        if isinstance(val, type) or isinstance(val, _OldClassType):
            type_obj = val
            val = val.__init__

        try:
            args, vargs, varkw, defaults = inspect.getargspec(val)
        except TypeError:
            # we're not doing inspect on a Python function...
            if sys.platform == 'cli':
                if type_obj is not None:
                    clr_type = clr.GetClrType(type_obj)
                    ctors = clr_type.GetConstructors()
                    return [self.get_ipy_sig(type_obj, ctor) for ctor in ctors]
                elif type(val) is types.BuiltinFunctionType:
                    return [self.get_ipy_sig(target, target.Targets[0]) for target in val.Overloads.Functions]
                elif type(val) is builtin_method_descriptor_type:
                    val = PythonOps.GetBuiltinMethodDescriptorTemplate(val)
                    return [self.get_ipy_sig(target, target.Targets[0]) for target in val.Overloads.Functions]
            raise

        remove_self = type_obj is not None or (type(val) is types.MethodType and 
                        ((sys.version >= '3.0' and val.__self__ is not None) or
                        (sys.version < '3.0' and val.im_self is not None)))

        if remove_self:
            # remove self for instance methods and types
            args = args[1:]
            
        if defaults is not None:
            defaults = [repr(default) for default in defaults]
        return [(doc, args, vargs, varkw, defaults)]
Exemple #3
0
def get_overloads(func, is_method = False):
    if type(func) == type(list.append):
        func = PythonOps.GetBuiltinMethodDescriptorTemplate(func)

    targets = func.Targets

    res = get_function_overloads(targets)

    return res