Skip to content

Move sys variable initialization from import.c to sysmodule.c #56807

Description

@ericsnowcurrently
BPO 12598
Nosy @ncoghlan, @pitrou, @vstinner, @benjaminp, @ericsnowcurrently
Files
  • sys_import_state.diff
  • 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 = <Date 2019-10-22.22:42:39.148>
    created_at = <Date 2011-07-20.23:24:44.285>
    labels = ['interpreter-core']
    title = 'Move sys variable initialization from import.c to sysmodule.c'
    updated_at = <Date 2019-10-22.22:42:39.147>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2019-10-22.22:42:39.147>
    actor = 'vstinner'
    assignee = 'eric.snow'
    closed = True
    closed_date = <Date 2019-10-22.22:42:39.148>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2011-07-20.23:24:44.285>
    creator = 'eric.snow'
    dependencies = []
    files = ['22707']
    hgrepos = []
    issue_num = 12598
    keywords = ['patch']
    message_count = 6.0
    messages = ['140769', '158637', '158650', '158653', '158670', '355164']
    nosy_count = 5.0
    nosy_names = ['ncoghlan', 'pitrou', 'vstinner', 'benjamin.peterson', 'eric.snow']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue12598'
    versions = ['Python 3.3']

    Activity

    1. ericsnowcurrently commented on Jul 20, 2011

      @ericsnowcurrently
      MemberAuthor

      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.

    2. ericsnowcurrently commented on Apr 18, 2012

      @ericsnowcurrently
      MemberAuthor

      The patch is out of date, but the question is still somewhat applicable.

    3. pitrou commented on Apr 18, 2012

      @pitrou
      Member

      This looks sensible.

    4. benjaminp commented on Apr 18, 2012

      @benjaminp
      Contributor

      I don't see the point.

    5. ncoghlan commented on Apr 18, 2012

      @ncoghlan
      Contributor

      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.

    6. vstinner commented on Oct 22, 2019

      @vstinner
      Member

      No activity for 7 years, I close the issue.

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions