Python 在给定参数字典的情况下,如何使用仅位置参数调用函数?

Python 在给定参数字典的情况下,如何使用仅位置参数调用函数?,python,signature,pep570,Python,Signature,Pep570,之前我使用了Signature.bind(argument_dict)将参数字典转换为BoundArguments对象,该对象具有可传递给函数的.args和.kwargs 定义foo(a:str,b:str,c:str):。。。 参数_dict={“a”:“a”,“c”:“c”,“b”:“b”} 进口检验 sig=检查签名(foo) 绑定参数=sig.bind(**argument\u dict) foo(*bound_arguments.args,**bound_arguments.kwarg

之前我使用了
Signature.bind(argument_dict)
将参数字典转换为
BoundArguments
对象,该对象具有可传递给函数的
.args
.kwargs

定义foo(a:str,b:str,c:str):。。。 参数_dict={“a”:“a”,“c”:“c”,“b”:“b”} 进口检验 sig=检查签名(foo) 绑定参数=sig.bind(**argument\u dict) foo(*bound_arguments.args,**bound_arguments.kwargs) 但是,当函数只有位置参数时,这似乎是不可能的

定义foo(a:str,/,b:str,*,c:str):。。。 进口检验 sig=检查签名(foo) 参数_dict={“a”:“a”,“b”:“b”,“c”:“c”} 绑定参数=sig.bind(**参数dict)#错误:“a”仅用于位置 在这种情况下,如何以编程方式调用函数


这是从参数字典构造
BoundArguments
的本机方法吗?

我只能找到这样的方法,使用dict中的仅位置参数:

pos_only = [k for k, v in sig.parameters.items() if v.kind is inspect.Parameter.POSITIONAL_ONLY]
positionals = [argument_dict.pop(k) for k in pos_only]
bound_arguments = sig.bind(*positionals, **argument_dict)