python类getargs()的实例源码

abc_test_interfaces.py 文件源码 项目:simphony-remote 作者: simphony 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def assertApplicationPolicyEqual(self, policy1, policy2, msg=None):
        args = _inspect.getargs(
            ABCApplicationPolicy.__init__.__code__).args[1:]
        for arg in args:
            if getattr(policy1, arg) != getattr(policy2, arg):
                raise self.failureException(msg)
interfaces.py 文件源码 项目:simphony-remote 作者: simphony 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __repr__(self):
        args = _inspect.getargs(ABCApplication.__init__.__code__).args[1:]

        return "<{cls}({spec})>".format(
            cls=self.__class__.__name__,
            spec=", ".join("{0}={1!r}".format(arg, getattr(self, arg))
                           for arg in args))
interfaces.py 文件源码 项目:simphony-remote 作者: simphony 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def __repr__(self):
        args = _inspect.getargs(
            ABCApplicationPolicy.__init__.__code__).args[1:]

        return "<{cls}({spec})>".format(
            cls=self.__class__.__name__,
            spec=", ".join("{0}={1!r}".format(arg, getattr(self, arg))
                           for arg in args))
turtle.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def getmethparlist(ob):
    """Get strings describing the arguments for the given object

    Returns a pair of strings representing function parameter lists
    including parenthesis.  The first string is suitable for use in
    function definition and the second is suitable for use in function
    call.  The "self" parameter is not included.
    """
    defText = callText = ""
    # bit of a hack for methods - turn it into a function
    # but we drop the "self" param.
    # Try and build one for Python defined functions
    args, varargs, varkw = inspect.getargs(ob.__code__)
    items2 = args[1:]
    realArgs = args[1:]
    defaults = ob.__defaults__ or []
    defaults = ["=%r" % (value,) for value in defaults]
    defaults = [""] * (len(realArgs)-len(defaults)) + defaults
    items1 = [arg + dflt for arg, dflt in zip(realArgs, defaults)]
    if varargs is not None:
        items1.append("*" + varargs)
        items2.append("*" + varargs)
    if varkw is not None:
        items1.append("**" + varkw)
        items2.append("**" + varkw)
    defText = ", ".join(items1)
    defText = "(%s)" % defText
    callText = ", ".join(items2)
    callText = "(%s)" % callText
    return defText, callText
python.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def getfuncargnames(function, startindex=None):
    # XXX merge with main.py's varnames
    #assert not inspect.isclass(function)
    realfunction = function
    while hasattr(realfunction, "__wrapped__"):
        realfunction = realfunction.__wrapped__
    if startindex is None:
        startindex = inspect.ismethod(function) and 1 or 0
    if realfunction != function:
        startindex += num_mock_patch_args(function)
        function = realfunction
    if isinstance(function, functools.partial):
        argnames = inspect.getargs(py.code.getrawcode(function.func))[0]
        partial = function
        argnames = argnames[len(partial.args):]
        if partial.keywords:
            for kw in partial.keywords:
                argnames.remove(kw)
    else:
        argnames = inspect.getargs(py.code.getrawcode(function))[0]
    defaults = getattr(function, 'func_defaults',
                       getattr(function, '__defaults__', None)) or ()
    numdefaults = len(defaults)
    if numdefaults:
        return tuple(argnames[startindex:-numdefaults])
    return tuple(argnames[startindex:])

# algorithm for sorting on a per-parametrized resource setup basis
# it is called for scopenum==0 (session) first and performs sorting
# down to the lower scopes such as to minimize number of "high scope"
# setups and teardowns
getargspec.py 文件源码 项目:blender 作者: gastrodia 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def getargspec(func):
        """Like inspect.getargspec but supports functools.partial as well."""
        if inspect.ismethod(func):
            func = func.__func__
        parts = 0, ()
        if type(func) is partial:
            keywords = func.keywords
            if keywords is None:
                keywords = {}
            parts = len(func.args), keywords.keys()
            func = func.func
        if not inspect.isfunction(func):
            raise TypeError('%r is not a Python function' % func)
        args, varargs, varkw = inspect.getargs(func.__code__)
        func_defaults = func.__defaults__
        if func_defaults is None:
            func_defaults = []
        else:
            func_defaults = list(func_defaults)
        if parts[0]:
            args = args[parts[0]:]
        if parts[1]:
            for arg in parts[1]:
                i = args.index(arg) - len(args)
                del args[i]
                try:
                    del func_defaults[i]
                except IndexError:
                    pass
        return inspect.ArgSpec(args, varargs, varkw, func_defaults)
ultratb.py 文件源码 项目:blender 作者: gastrodia 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def with_patch_inspect(f):
    """decorator for monkeypatching inspect.findsource"""

    def wrapped(*args, **kwargs):
        save_findsource = inspect.findsource
        save_getargs = inspect.getargs
        inspect.findsource = findsource
        inspect.getargs = getargs
        try:
            return f(*args, **kwargs)
        finally:
            inspect.findsource = save_findsource
            inspect.getargs = save_getargs

    return wrapped
getargspec.py 文件源码 项目:yatta_reader 作者: sound88 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def getargspec(func):
        """Like inspect.getargspec but supports functools.partial as well."""
        if inspect.ismethod(func):
            func = func.__func__
        parts = 0, ()
        if type(func) is partial:
            keywords = func.keywords
            if keywords is None:
                keywords = {}
            parts = len(func.args), keywords.keys()
            func = func.func
        if not inspect.isfunction(func):
            raise TypeError('%r is not a Python function' % func)
        args, varargs, varkw = inspect.getargs(func.__code__)
        func_defaults = func.__defaults__
        if func_defaults is None:
            func_defaults = []
        else:
            func_defaults = list(func_defaults)
        if parts[0]:
            args = args[parts[0]:]
        if parts[1]:
            for arg in parts[1]:
                i = args.index(arg) - len(args)
                del args[i]
                try:
                    del func_defaults[i]
                except IndexError:
                    pass
        return inspect.ArgSpec(args, varargs, varkw, func_defaults)


问题


面经


文章

微信
公众号

扫码关注公众号