当前位置: 首页>>代码示例>>Python>>正文


Python FunctionType.__doc__方法代码示例

本文整理汇总了Python中types.FunctionType.__doc__方法的典型用法代码示例。如果您正苦于以下问题:Python FunctionType.__doc__方法的具体用法?Python FunctionType.__doc__怎么用?Python FunctionType.__doc__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types.FunctionType的用法示例。


在下文中一共展示了FunctionType.__doc__方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: buildFunction

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
def buildFunction(baseFunc, code=None, glbls=None,
                  name=None, defaults=None,
                  kwdefaults=None, closure=None,
                  annotations=None, doc=None, dct=None):

    resf = None

    def _f():
        pass

    if hasattr(_f, 'func_code'):
        # Python 2.x
        resf = FunctionType(code or baseFunc.func_code,
                            glbls or baseFunc.func_globals,
                            name or baseFunc.func_name,
                            defaults or baseFunc.func_defaults,
                            closure or baseFunc.func_closure)
        resf.func_dict = dct or baseFunc.func_dict
        resf.func_doc = doc or baseFunc.func_doc

    else:
        # Python 3.x
        resf = FunctionType(code or baseFunc.__code__,
                            glbls or baseFunc.__globals__,
                            name or baseFunc.__name__,
                            defaults or baseFunc.__defaults__,
                            closure or baseFunc.__closure__)
        resf.__kwdefaults__ = kwdefaults or baseFunc.__kwdefaults__
        resf.__annotations__ = annotations or baseFunc.__annotations__
        resf.__dict__ = dct or baseFunc.__dict__
        resf.__doc__ = doc or baseFunc.__doc__

    return resf
开发者ID:DirectXMan12,项目名称:should_be,代码行数:35,代码来源:core.py

示例2: chained_function

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
 def chained_function(meta, func, mod):
     d = ModuleChainedDict(mod.__dict__, func.__globals__)
     newfunc = FunctionType(func.__code, d)
     newfunc.__doc__ = func.__doc__
     newfunc.__defaults__ = newfunc.__defaults__
     newfunc.__kwdefaults__ = func.__kwdefaults__
     return newfunc
开发者ID:felipecruz,项目名称:pyjulia,代码行数:9,代码来源:core.py

示例3: handle_deffun

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
 def handle_deffun(self, func, fdict, fdoc, remote_globals):
   func = self.unpack(func)
   g = globals()
   glbls = {k:g[k] for k in remote_globals if k in g} if remote_globals is not None else g.copy()
   glbls.update(func[1])
   func[1].update(glbls)
   f = FunctionType(*func)
   f.__dict__ = self.unpack(fdict)
   f.__doc__ = self.unpack(fdoc)
   return self.pack(f)
开发者ID:heartbleeded,项目名称:qira,代码行数:12,代码来源:remoteobj.py

示例4: __new__

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
    def __new__(cls, mplayer=MPLAYER_PATH, pipe=PIPE_PATH, 
                     stdout=STDOUT_PATH, pid=PID_PATH, debug=False):

        def _doc_creator(item):
            ## Doc creator for the command
            doc_info  = item['comment']
            py_command = item['pycommand']
            doc = '%s\n%s' % (py_command, doc_info)
            return doc

        ## Creating new class methods from mplayer cmdlist_dict
        cmdlist_dict = CmdDictGenerator(mplayer).get_cmdlist()
        for item in cmdlist_dict.keys():
            if item == 'get_property': continue
            if item == 'set_property': continue
            #if item == 'set_property_osd': continue
            doc = _doc_creator(cmdlist_dict[item])
            # Creating a dictionary that would include variables from 
            # item and globals() (excluding locals()).
            # This is necessary for passing it to a new method.
            method_dict = {'item': cmdlist_dict[item]}
            for i in globals().keys():
                if i in locals().keys(): continue
                method_dict[i] = globals()[i]
            # Creating a function
            if 'get' not in item:
                if len(cmdlist_dict[item]['types']) != 0:
                    # If list of types contains some types
                    new_method = FunctionType(cls._new_args_method.func_code,
                                              method_dict,
                                              item)
                else:
                    # If list of types is empty
                    new_method = FunctionType(cls._new_simple_method.func_code,
                                              method_dict,
                                              item)
            else:
                new_method = FunctionType(cls._new_get_method.func_code,
                                          method_dict,
                                          item)
            # Adding doc, editing name
            new_method.__doc__ = doc
            new_method.__name__ = item
            # Adding function to this class as a method
            setattr(cls, item, new_method)
        # Create 'properties' property and 
        # making it use the doc from Properties class
        properties_class = Properties()
        def get_properties(self):
            return properties_class
        properties = property(fget=get_properties, 
                              doc=Properties.__doc__)
        setattr(cls, 'properties', properties)
        return super(Player, cls).__new__(cls)
开发者ID:Seg-mel,项目名称:mplayer_control,代码行数:56,代码来源:player.py

示例5: interpolate

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
    def interpolate(self, obj, name):
        """Inject the formatted listing in the second blank line of `name`."""
        f = getattr(obj, name)
        f2 = FunctionType(f.__code__, f.__globals__, name=f.__name__, argdefs=f.__defaults__, closure=f.__closure__)

        # Conveniently the original docstring is on f2, not the new ones if
        # inheritence is happening. I have no idea why.
        t = f2.__doc__.split("\n\n")
        t.insert(2, self.formatted_listing())
        f2.__doc__ = "\n\n".join(t)

        setattr(obj, name, f2)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:14,代码来源:_misc.py

示例6: reader

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
def reader(name=None, doc=None):
    """Construct a new unified input/output reader.

    This method is required to create a new copy of the
    :func:`astropy.io.registry.read` with a dynamic docstring.

    Returns
    -------
    read : `function`
        A copy of the :func:`astropy.io.registry.read` function
    """
    func = FunctionType(read.func_code, read.func_globals,
                        name or read.func_name, read.func_defaults,
                        read.func_closure)
    if doc is not None:
        func.__doc__ = doc.strip('\n ')
    return func
开发者ID:JackieXie168,项目名称:gwpy,代码行数:19,代码来源:__init__.py

示例7: writer

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
def writer(doc=None):
    """Construct a new unified input/output writeer.

    This method is required to create a new copy of the
    :func:`astropy.io.registry.write` with a dynamic docstring.

    Returns
    -------
    write : `function`
        A copy of the :func:`astropy.io.registry.write` function
    """
    func = FunctionType(write.func_code, write.func_globals,
                        write.func_name, write.func_defaults,
                        write.func_closure)
    if doc is not None:
        func.__doc__ = doc.strip('\n ')
    return func
开发者ID:bfarr,项目名称:gwpy,代码行数:19,代码来源:__init__.py

示例8: interpolate

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
    def interpolate(self, obj, name):
        """Inject the formatted listing in the second blank line of `name`."""
        # Py2/3 compatible way of calling getattr(obj, name).__func__
        f = getattr(obj, name).__get__(None, type(None))

        if hasattr(f, 'func_code'):
            f2 = FunctionType(f.func_code, f.func_globals, name=f.func_name,
                              argdefs=f.func_defaults, closure=f.func_closure)
        else:
            f2 = FunctionType(f.__code__, f.__globals__, name=f.__name__,
                              argdefs=f.__defaults__, closure=f.__closure__)
        # Conveniently the original docstring is on f2, not the new ones if
        # inheritence is happening. I have no idea why.
        t = f2.__doc__.split("\n\n")
        t.insert(2, self.formatted_listing())
        f2.__doc__ = "\n\n".join(t)

        setattr(obj, name, f2)
开发者ID:bctaylor,项目名称:scikit-bio,代码行数:20,代码来源:_misc.py

示例9: loads_function

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
def loads_function(s):
    '''Restores a function serialized with :func:`dumps_function`.'''
    name, code, globals_, defaults, closure, func_dict, doc, qualname, kwdefaults, annotations = loads(s)
    code = marshal.loads(code)
    for k, v in globals_.items():
        if isinstance(v, Module):
            globals_[k] = v.mod
    if closure is not None:
        import ctypes
        ctypes.pythonapi.PyCell_New.restype = ctypes.py_object
        ctypes.pythonapi.PyCell_New.argtypes = [ctypes.py_object]
        closure = tuple(ctypes.pythonapi.PyCell_New(c) for c in closure)
    globals_['__builtins__'] = __builtins__
    r = FunctionType(code, globals_, name, defaults, closure)
    r.__dict__ = func_dict
    r.__doc__ = doc
    r.__qualname__ = qualname
    r.__kwdefaults__ = kwdefaults
    r.__annotations__ = annotations
    return r
开发者ID:tobiasleibner,项目名称:pymor,代码行数:22,代码来源:pickle.py

示例10: _clone

# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __doc__ [as 别名]
def _clone(origin_fun, new_fun_name, name, extra=None):
    # update the checkers/accessors dico
    original_checkers = origin_fun.checker.arg_type_list
    new_dict = dict(original_checkers)

    if extra is not None:
        new_dict.update(extra)

    # clone the function
    new_fun = FunctionType(code=origin_fun.__code__,
                           globals=origin_fun.__globals__,
                           name=new_fun_name,
                           argdefs=origin_fun.__defaults__,
                           closure=origin_fun.__closure__)

    # apply decorator
    fun_decorator = shellMethod(**new_dict)
    fun_decorator(new_fun)

    # updat the docstring
    new_fun.__doc__ = new_fun.__doc__.replace("environment", name)

    return new_fun
开发者ID:djoproject,项目名称:pyshell,代码行数:25,代码来源:parameter.py


注:本文中的types.FunctionType.__doc__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。