Python 语法中的 FPDEF 和 TFPDEF 是什么意思?

What FPDEF and TFPDEF mean in Python grammar?

我读了 Python 的语法文件 (https://docs.python.org/3/reference/grammar.html) 但我不明白 TFPDEF 和 FPDEF 是什么意思。我希望你能帮助我:)

Python 3.8 version 有更多评论解释它

它们基本上只是 NAMEs(T 变体有一个可选的类型声明),所以:

def foo(a, b): pass

将通过以下规则子集进行解析:

funcdef: 'def' NAME parameters ':' func_body_suite

parameters: '(' [typedargslist] ')'

typedargslist: tfpdef (',' tfpdef)*

tfpdef: NAME

func_body_suite: simple_stmt

simple_stmt: small_stmt NEWLINE

small_stmt: pass_stmt

根据 [Python 3]: Full Grammar specification 中此类标识符的命名方式,可以得出结论(因为我没有看到任何正式声明):

  • tfpdef:

    • 用于描述类型参数(typedargslist 元素)
    • 代表:typed f函数p参数def 初始化
  • fpdef:

    • 没看到,但它可能指的是参数或参数(一般来说)

还有一个vfpdef(用来描述一个vararg)。我猜 v 的来源很明显。