New submission from Christian Heimes <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue42404>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com