[New-bugs-announce] [issue42404] clinic: add option to pass module object to converter function

Christian Heimes report at bugs.python.org
Thu Nov 19 06:40:44 EST 2020


New submission from Christian Heimes <lists at cheimes.de>:

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

----------
components: Argument Clinic
messages: 381406
nosy: christian.heimes, corona10, larry, vstinner
priority: normal
severity: normal
status: open
title: clinic: add option to pass module object to converter function
type: enhancement
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42404>
_______________________________________


More information about the New-bugs-announce mailing list