Instance Method Objects - Python 3.12.0a3 documentation 编辑
An instance method is a wrapper for a PyCFunction
and the new way to bind a PyCFunction
to a class object. It replaces the former call PyMethod_New(func, NULL, class)
.
- PyTypeObject PyInstanceMethod_Type
This instance of
PyTypeObject
represents the Python instance method type. It is not exposed to Python programs.
- int PyInstanceMethod_Check(PyObject *o)
Return true if o is an instance method object (has type
PyInstanceMethod_Type
). The parameter must not beNULL
. This function always succeeds.
- PyObject *PyInstanceMethod_New(PyObject *func)
- Return value: New reference.
Return a new instance method object, with func being any callable object. func is the function that will be called when the instance method is called.
- PyObject *PyInstanceMethod_Function(PyObject *im)
- Return value: Borrowed reference.
Return the function object associated with the instance method im.
- PyObject *PyInstanceMethod_GET_FUNCTION(PyObject *im)
- Return value: Borrowed reference.
Macro version of
PyInstanceMethod_Function()
which avoids error checking.
Method Objects
Methods are bound function objects. Methods are always bound to an instance of a user-defined class. Unbound methods (methods bound to a class object) are no longer available.
- PyTypeObject PyMethod_Type
This instance of
PyTypeObject
represents the Python method type. This is exposed to Python programs astypes.MethodType
.
- int PyMethod_Check(PyObject *o)
Return true if o is a method object (has type
PyMethod_Type
). The parameter must not beNULL
. This function always succeeds.
- PyObject *PyMethod_New(PyObject *func, PyObject *self)
- Return value: New reference.
Return a new method object, with func being any callable object and self the instance the method should be bound. func is the function that will be called when the method is called. self must not be
NULL
.
- PyObject *PyMethod_Function(PyObject *meth)
- Return value: Borrowed reference.
Return the function object associated with the method meth.
- PyObject *PyMethod_GET_FUNCTION(PyObject *meth)
- Return value: Borrowed reference.
Macro version of
PyMethod_Function()
which avoids error checking.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论