Python C Extension - Why are methods that use keyword arguments cast to PyCFunction

前端 未结 1 482

I\'ve am learning about Python-C extensions and am puzzled as to why methods that use keyword arguments must be cast to PyCFunctions.

My understanding of a PyCFuncti

1条回答
  •  有刺的猬
    2021-01-12 15:18

    If your function handles keyword arguments, then it must correspond to a PyCFunctionWithKeywords. However, C doesn’t do overloading, and the structure built by PyMethodDef is defined to expect a PyCFunction, rather than, say, a completely unchecked void *. So you must cast your PyCFunctionWithKeywords to a PyCFunction to stop the compiler complaining, that’s all.

    Remember that you must also pass METH_KEYWORDS in the flags to tell Python that your function has the signature of a PyCFunctionWithKeywords, not a PyCFunction.

    0 讨论(0)
提交回复
热议问题