You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Move sys variable initialization from import.c to sysmodule.c #56807
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/ericsnowcurrently'closed_at=<Date2019-10-22.22:42:39.148>created_at=<Date2011-07-20.23:24:44.285>labels= ['interpreter-core']
title='Move sys variable initialization from import.c to sysmodule.c'updated_at=<Date2019-10-22.22:42:39.147>user='https://github.com/ericsnowcurrently'
Several import-related sys variables are set in _PyImportHooks_Init (in Python/import.c), which is called in Python/pythonrun.c. I have included a patch that moves that initialization from _PyImportHooks_Init to a new _SysImportState_Init function in Python/sysmodule.c, which is then called from _PyImportHooks_Init.
This may seem like an unnecessary change, but sysmodule.c is the obvious place to find the initialization of sys variables. Other than in pythonrun.c, import.c is the only place that sys variables are set outside of sysmodule.c.
Finally, several import related projects[1] are coming up that will impact import.c and _PyImportHooks_Init specifically. This change helps clean up import.c a little in preparation for those projects, and isolates out of import.c at least one thing that should be kept safe during any import.c refactoring.
[1] see issue bpo-2377, PEP-402, and the GSOC import engine project.
It's about navigability/discovery of the source - to find out how the sys module gets initialised, you currently have to look in multiple places. The idea of the patch is to simplify that to the one logical place: sysmodule.c
However, I'm not sure it's right to actually *move* the full import state initialisation. A simple *indirection* (pythonrun.c -> sysmodule.c -> import.c) would solve the navigability problem while also retaining some level of encapsulation for the import state initialisation.
Activity
ericsnowcurrently commentedon Jul 20, 2011
Several import-related sys variables are set in _PyImportHooks_Init (in Python/import.c), which is called in Python/pythonrun.c. I have included a patch that moves that initialization from _PyImportHooks_Init to a new _SysImportState_Init function in Python/sysmodule.c, which is then called from _PyImportHooks_Init.
This may seem like an unnecessary change, but sysmodule.c is the obvious place to find the initialization of sys variables. Other than in pythonrun.c, import.c is the only place that sys variables are set outside of sysmodule.c.
Finally, several import related projects[1] are coming up that will impact import.c and _PyImportHooks_Init specifically. This change helps clean up import.c a little in preparation for those projects, and isolates out of import.c at least one thing that should be kept safe during any import.c refactoring.
[1] see issue bpo-2377, PEP-402, and the GSOC import engine project.
ericsnowcurrently commentedon Apr 18, 2012
The patch is out of date, but the question is still somewhat applicable.
pitrou commentedon Apr 18, 2012
This looks sensible.
benjaminp commentedon Apr 18, 2012
I don't see the point.
ncoghlan commentedon Apr 18, 2012
It's about navigability/discovery of the source - to find out how the sys module gets initialised, you currently have to look in multiple places. The idea of the patch is to simplify that to the one logical place: sysmodule.c
However, I'm not sure it's right to actually *move* the full import state initialisation. A simple *indirection* (pythonrun.c -> sysmodule.c -> import.c) would solve the navigability problem while also retaining some level of encapsulation for the import state initialisation.
vstinner commentedon Oct 22, 2019
No activity for 7 years, I close the issue.