This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Document how to make classes in the C API.
Type: Stage: resolved
Components: Documentation, Extension Modules Versions: Python 3.7, Python 3.6, Python 3.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Decorater, docs@python, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-05-17 17:56 by Decorater, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg293863 - (view) Author: Decorater (Decorater) * Date: 2017-05-17 17:56
On the C API, it tells how to make modules, functions, variables, and other things, but what about classes?

Like for example if you wanted to make a class with all of the methods having to use direct C Code which would then be converted to PyObject *'s for returning the information the C Code would normally return.

Not only that but also being able to create class instance variables using the C API as well.

Like for example here is an example class (As it would be if it was written in python):

class Example:
    def __init__(self): = None  # None being a place holder for now.

    def somefunction(self):
        # C Code here. = ret  # return value for the C Code.

Yes, there are better ways than writing the return data to the instance variable and returning it. That is just an example, I have classes that uses them for other things that does not return anything making the instance variables be the only way to get the data.

But yeah long story short I think creating classes with the C API should be documented if not already, or at least an example of doing one to be added as an guide for others wondering how to use the C API to make their own (non exception) classes.
msg293864 - (view) Author: Decorater (Decorater) * Date: 2017-05-17 18:03
Hmm seems that when looking at the exports in python36.dll that the following functions seem to not be documented as far as I seen:


There might be more functions dealing with classes that are not documented. However looking through the whole exports would take to long as there are so many.
msg293865 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-17 18:07
This is documented. See
msg293880 - (view) Author: Decorater (Decorater) * Date: 2017-05-17 19:15
Still it does look the functions lited in the second comment are undocumented.

However on the last function I did find 1 thing However it was not what I was looking for. What I actually was looking for was the args for the 3 functions and description on what it does and all that similar to how this function is documented:

PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args)
Return value: New reference.
Call a callable Python object callable_object, with arguments given by the tuple args. If no arguments are needed, then args may be NULL. Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression callable_object(*args).


This is actually the reason why the issue was opened as the functions was not documented like this.
msg293884 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-17 20:05
The title of this issue is "Document how to make classes in the C API." This already is documented.

For documenting the PyClassMethod* names open a new issue.
Date User Action Args
2022-04-11 14:58:46adminsetgithub: 74575
2017-05-17 20:05:35serhiy.storchakasetstatus: open -> closed

messages: + msg293884
2017-05-17 19:17:41Decoratersetstatus: closed -> open
2017-05-17 19:15:28Decoratersetmessages: + msg293880
2017-05-17 18:07:58serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg293865

resolution: not a bug
stage: resolved
2017-05-17 18:03:21Decoratersetmessages: + msg293864
2017-05-17 17:56:45Decoratercreate