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.

classification
Title: clinic: add option to pass module object to converter function
Type: enhancement Stage:
Components: Argument Clinic Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, corona10, larry, vstinner
Priority: normal Keywords:

Created on 2020-11-19 11:40 by christian.heimes, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg381406 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-11-19 11:40
Sometimes the converter function for CConverter must access the current module object in order to access the current module state. Currently CConverter subclasses have no easy way to pass the module to the converter function. It would be fantastic if easier CConverter would get an option to pass the module.

Example:

GH-23398 converts the struct module to multiphase initialization. The struct module has a converter for cached struct definitions. The cache used to be a module level object. It is now an interpreter scoped object. I used a custom parse_arg() function to pass the module object:


class cache_struct_converter(CConverter):
    type = 'PyStructObject *'
    converter = 'cache_struct_converter'
    c_default = "NULL"

    def parse_arg(self, argname, displayname):
        return """
            if (!{converter}(module, {argname}, &{paramname})) {{{{
                goto exit;
            }}}}
            """.format(argname=argname, paramname=self.name,
                       converter=self.converter)

    def cleanup(self):
        return "Py_XDECREF(%s);\n" % self.name
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86570
2020-11-19 11:40:44christian.heimescreate