本文整理汇总了Python中types.SimpleNamespace.params方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleNamespace.params方法的具体用法?Python SimpleNamespace.params怎么用?Python SimpleNamespace.params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.SimpleNamespace
的用法示例。
在下文中一共展示了SimpleNamespace.params方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mcmcmc_mc_step_run
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import params [as 别名]
def test_mcmcmc_mc_step_run():
tmp_file = br.TempFile()
walker = SimpleNamespace(function=lambda func_args: 1234, params=[], proposed_score_file=tmp_file)
mcmcmc.MCMCMC.mc_step_run(walker, ["foo"])
assert tmp_file.read() == "1234"
tmp_file.clear()
walker.params = ["bar", "baz"]
walker.function = lambda func_args, params: 4321
mcmcmc.MCMCMC.mc_step_run(walker, ["foo"])
assert tmp_file.read() == "4321"
示例2: extract_function_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import params [as 别名]
def extract_function_doc(state: State, parent, path: List[str], function) -> List[Any]:
assert inspect.isfunction(function) or inspect.ismethod(function) or inspect.isroutine(function)
# Extract the signature from the docstring for pybind11, since it can't
# expose it to the metadata: https://github.com/pybind/pybind11/issues/990
# What's not solvable with metadata, however, are function overloads ---
# one function in Python may equal more than one function on the C++ side.
# To make the docs usable, list all overloads separately.
if state.config['PYBIND11_COMPATIBILITY'] and function.__doc__.startswith(path[-1]):
funcs = parse_pybind_docstring(state, path[-1], function.__doc__)
overloads = []
for name, summary, args, type in funcs:
out = Empty()
out.name = path[-1]
out.params = []
out.has_complex_params = False
out.has_details = False
# TODO: external summary for functions
out.summary = summary
# Don't show None return type for void functions
out.type = None if type == 'None' else type
# There's no other way to check staticmethods than to check for
# self being the name of first parameter :( No support for
# classmethods, as C++11 doesn't have that
out.is_classmethod = False
if inspect.isclass(parent) and args and args[0][0] == 'self':
out.is_staticmethod = False
else:
out.is_staticmethod = True
# Guesstimate whether the arguments are positional-only or
# position-or-keyword. It's either all or none. This is a brown
# magic, sorry.
# For instance methods positional-only argument names are either
# self (for the first argument) or arg(I-1) (for second
# argument and further). Also, the `self` argument is
# positional-or-keyword only if there are positional-or-keyword
# arguments afgter it, otherwise it's positional-only.
if inspect.isclass(parent) and not out.is_staticmethod:
assert args and args[0][0] == 'self'
positional_only = True
for i, arg in enumerate(args[1:]):
name, type, default = arg
if name != 'arg{}'.format(i):
positional_only = False
break
# For static methods or free functions positional-only arguments
# are argI.
else:
positional_only = True
for i, arg in enumerate(args):
name, type, default = arg
if name != 'arg{}'.format(i):
positional_only = False
break
for i, arg in enumerate(args):
name, type, default = arg
param = Empty()
param.name = name
# Don't include redundant type for the self argument
if name == 'self': param.type = None
else: param.type = type
param.default = html.escape(default or '')
if type or default: out.has_complex_params = True
# *args / **kwargs can still appear in the parsed signatures if
# the function accepts py::args / py::kwargs directly
if name == '*args':
param.name = 'args'
param.kind = 'VAR_POSITIONAL'
elif name == '**kwargs':
param.name = 'kwargs'
param.kind = 'VAR_KEYWORD'
else:
param.kind = 'POSITIONAL_ONLY' if positional_only else 'POSITIONAL_OR_KEYWORD'
out.params += [param]
overloads += [out]
return overloads
# Sane introspection path for non-pybind11 code
else:
out = Empty()
out.name = path[-1]
out.params = []
out.has_complex_params = False
out.has_details = False
# TODO: external summary for functions
out.summary = extract_summary(state, {}, [], function.__doc__)
# Decide if classmethod or staticmethod in case this is a method
if inspect.isclass(parent):
#.........这里部分代码省略.........