GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Split Up _testsinglephase.c and _testmultiphase.c · Issue #124983 · python/cpython

Split Up _testsinglephase.c and _testmultiphase.c #124983

New issue
Copy link
New issue
Copy link
Open
Open
Split Up _testsinglephase.c and _testmultiphase.c#124983
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtestsTests in the Lib/test dirTests in the Lib/test dirtype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)

Description

@ericsnowcurrently
ericsnowcurrently
opened on Oct 4, 2024
Issue body actions

(low priority)

Modules/_testsinglephase.c and Modules/_testmultiphase.c both contain the implementations of multiple modules. We should consider splitting up both files, so each contained module has its own file.

Here are several reasons why this may be worth doing:

  • testing with a module hidden in another's .so file is awkward and makes those tests harder to understand
  • it's easier to accidentally leak C-module global data between modules when they are implemented in the same file
  • when adding a new module, it's trickier (less familiar) to implement it in an existing file than in a new file 1

Furthermore, both files were added to test specific import functionality. As far as I can tell2, that never included any need for the multiple-modules-in-one-file approach. However, currently they are the only place where we're testing the feature, regardless of how unintentionally or superficially. gh-124978 targets fixing that lack of explicit testing, including moving away from _testsinglephase.c and _testmultiphase.c (e.g. using the dedicated Modules/_testimportmultiple.c).

All that said, splitting up the files is a fairly low priority task. The status quo isn't ideal but it isn't that bad either.


Here's how I see us taking care of this:

  1. make sure multiple-modules-in-one-file is tested via the dedicated Modules/_testimportmultiple.c 2 (see gh-124978)
  2. create the Modules/_testsinglephase directory
  3. move each module from _testsinglephase.c to its own file (see the devguide)
  4. update the relevant tests
  5. delete Modules/_testsinglephase.c
  6. repeat steps 2-5 for Modules/_testmultiphase.c

Footnotes

  1. However, adding it to an existing file is also simpler in how adding a new file involves tweaking the build. See the devguide. ↩

  2. I personally added Modules/_testsinglephase.c and @encukou added _testmultiphase.c. ↩ ↩2

Activity

  1. ericsnowcurrently
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    3.14bugs and security fixesbugs and security fixes
    on Oct 4, 2024
  2. ericsnowcurrently commented on Oct 4, 2024

    @ericsnowcurrently
    ericsnowcurrently
    on Oct 4, 2024
    MemberAuthor
    More actions

    CC @encukou

  3. encukou commented on Oct 7, 2024

    @encukou
    encukou
    on Oct 7, 2024
    Member
    More actions

    I'm honestly a bit surprised that you'd prefer dealing with multiple .so/.dll files.
    Similar code split/repeated across several files is also hard to understand, and tests are exactly where leaking C globals is least dangerous.

    But, that's all vibes. If you care strongly enough, go ahead and refactor.

  4. StanFromIreland
    added
    type-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
    and removed
    3.14bugs and security fixesbugs and security fixes
    on Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtestsTests in the Lib/test dirTests in the Lib/test dirtype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.