本文整理汇总了Python中types.FunctionType.__kwdefaults__方法的典型用法代码示例。如果您正苦于以下问题:Python FunctionType.__kwdefaults__方法的具体用法?Python FunctionType.__kwdefaults__怎么用?Python FunctionType.__kwdefaults__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.FunctionType
的用法示例。
在下文中一共展示了FunctionType.__kwdefaults__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chained_function
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __kwdefaults__ [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
示例2: buildFunction
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __kwdefaults__ [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
示例3: loads_function
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __kwdefaults__ [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
示例4: patched_function
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import __kwdefaults__ [as 别名]
def patched_function(function):
new_function = FunctionType(six.get_function_code(function), globals())
if six.PY3:
new_function.__kwdefaults__ = function.__kwdefaults__
new_function.__defaults__ = function.__defaults__
return new_function