parameter_list ::= (defparameter ",")* #[1]
| "*" [parameter] ("," defparameter)* ["," "**" parameter] #[2]
| "**" parameter #[3]
| defparameter [","] ) #[4]
(为了清楚起见,我添加了#[num])
我看不出它与以下函数定义的匹配程度如何:
def foo(a, *, b=10): pass
一个明显的规则,即假设def foo(a,*,b = 10)形式的定义将属于#[2],它允许*符号分离仅关键字参数.
但是根据我的想法,foo的规则必须是#[1]和#[2]的组合:
parameter_list ::= (defparameter ",")* "*" [parameter] ("," defparameter)* ["," "**" parameter]
由于规则#[1]和#[2]似乎并不完全符合本案例.
我在这里错过了什么?
解决方法:
形式语法似乎缺少一个左括号.最后一个关闭的东西与任何东西都不匹配,如果你看一下the Python 2 version,那就很有意义了:
parameter_list ::= (defparameter ",")*
( "*" identifier ["," "**" identifier]
| "**" identifier
| defparameter [","] )
所以请把它读作:
parameter_list ::= (defparameter ",")*
( "*" [parameter] ("," defparameter)* ["," "**" parameter]
| "**" parameter
| defparameter [","] )
有人可能会取代(用a |同时重新调整事物.
标签:python,syntax,python-3-x
来源: https://codeday.me/bug/20190623/1270625.html