[New-bugs-announce] [issue13431] Pass context information into the extension module init function

Stefan Behnel report at bugs.python.org
Sat Nov 19 10:16:48 CET 2011

New submission from Stefan Behnel <scoder at users.sourceforge.net>:

This is a follow-up to issue 13429, which deals with setting __file__ on newly created extension modules earlier than it is currently the case.

Currently, the module init function of extension modules lacks a way to find out the context in which it is being imported, e.g. its package path or its location in the file system. This makes it tricky for extension modules to do things like loading package resources or using relative imports at init time.

This can be fixed by allowing the init function to take a context struct as argument, which would contain object pointers to the FQ package name and file path, and potentially other information.

I think this would be backwards compatible to existing code, because C should allow the caller of the init function to pack additional arguments on the stack that the called function simply doesn't care about. From CPython 3.3 on, however, new and updated code could benefit from this feature.

components: Extension Modules, Interpreter Core
messages: 147931
nosy: scoder
priority: normal
severity: normal
status: open
title: Pass context information into the extension module init function
type: feature request
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list