The sys and builtins modules are special in that they are initialized early in interpreter startup, mostly before the import system. They aren't initialized like other modules. Furthermore, the data they expose is fundamental to the interpreter. Reloading the modules doesn't make much sense.
The simplest thing to do is to disallow manually loading them (e.g. via the loader). At the very least we should handle m_copy for these modules carefully. (This came up while working on gh-101660.)
I'm leaving this open since we haven't settled whether or not we should disallow directly loading sys/builtins. (That isn't critical to settle in the short-term, so I'm not going to focus much on it for now.)
Activity
gh-102660: Handle m_copy Specially for the sys and builtins Modules (g…
ericsnowcurrently commented on Mar 14, 2023
I'm leaving this open since we haven't settled whether or not we should disallow directly loading sys/builtins. (That isn't critical to settle in the short-term, so I'm not going to focus much on it for now.)
Merge branch 'main' into inlinecomp2
gh-102660: Fix Refleaks in import.c (#102744)
Merge branch 'main' into inlinecomp2
pythongh-102660: Handle m_copy Specially for the sys and builtins Mod…
pythongh-102660: Fix Refleaks in import.c (python#102744)
gh-102660: Fix is_core_module() (gh-103257)
pythongh-102660: Fix is_core_module() (pythongh-103257)
pythongh-102660: Handle m_copy Specially for the sys and builtins Mod…
pythongh-102660: Fix Refleaks in import.c (python#102744)
pythongh-102660: Fix is_core_module() (pythongh-103257)
hugovk commented on Mar 15, 2024
Triage: can this be closed or is there more to do?
Edit: I see this was recently move to "Todo" so sounds like there is more. Thanks!