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 — Should we test `-X lazy_imports=all` more? · Issue #149640 · python/cpython

Should we test -X lazy_imports=all more? #149640

New issue
Copy link
New issue
Copy link
Closed
Closed
Should we test -X lazy_imports=all more?#149640
Copy link
Labels
3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixestestsTests in the Lib/test dirTests in the Lib/test dirtopic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@JelleZijlstra
JelleZijlstra
opened on May 10, 2026
Issue body actions

Bug report

Bug description:

Inspired by #149321 I decided to see how well the test suite works with PYTHON_LAZY_IMPORTS=all / -X lazy_imports=all, which makes all imports lazy. It's nowhere near as bad as the none option that we're considering removing, but a few parts of the stdlib are broken, and it seems worth considering if we want to fix these.

Concrete issues I noticed:

  • PEP 810 lazy from imports ignore module __getattr__ when reifying #144957 breaks test_typing
  • test_unittest fails because unittest.main becomes a module instead of a function.
  • test_struct is broken because of a test that does exec("import struct") in a function; lazy imports are disallowed within functions. Similar issues affect test_enum, test_traceback, and test_future.
  • test_symtable is broken because it fills its _flags list by iterating over globals(), which means it starts containing lazy import marker objects. Similarly test_inspect breaks because it iterates over vars() of a module.

A few tests fail for legitimate reasons; test_compileall tests that an import triggers pyc compilation; test_builtin asserts that __import__ is used when in fact __lazy_import__ gets used.

Full list of failed modules on my machine:

test.test_future_stmt.test_future
test.test_inspect.test_inspect
test.test_pydoc.test_pydoc
test___all__
test__interpreters
test_builtin
test_capi
test_clinic
test_compileall
test_crossinterp
test_datetime
test_enum
test_generated_cases
test_idle
test_import
test_importlib
test_interpreters
test_json
test_lazy_import
test_struct
test_subprocess
test_symtable
test_tools
test_trace
test_traceback
test_tracemalloc
test_typing
test_unittest
test_xmlrpc
test_zipfile

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

  • gh-150565: Add additional tests for Lazy Imports #149739
  • gh-149640: Add new GitHub action to test lazy_imports=all against test suite #151090
  • gh-149640: Add new GitHub action to test lazy_imports=all against test suite #151105
Reacted by Dawid Konrad Kohnke

Activity

  1. JelleZijlstra
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.15bugs and security fixesbugs and security fixes
    topic-lazy-imports
    on May 10, 2026
  2. JelleZijlstra commented on May 10, 2026

    @JelleZijlstra
    JelleZijlstra
    on May 10, 2026
    MemberAuthor
    More actions

    And to be clear the outcome I'm looking for here is that we start testing lazy_imports=all in some kind of CI (a buildbot?) and fix the current issues, either by skipping the test conditionally or by fixing some aspect of the implementation.

    I'm now looking into the exec issue which feels like a bug; the unittest issue may also be a bug but I need to look further.

  3. StanFromIreland
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on May 10, 2026
  4. brittanyrey commented on Jun 9, 2026

    @brittanyrey
    brittanyrey
    on Jun 9, 2026
    Contributor
    More actions

    Attempting to add the CI in the linked PR.
    Also adding an exclusion list for failing tests to steadily chip away at

    Reacted by Dawid Konrad Kohnke
  5. serhiy-storchaka
    added this to Unittest & doctest issueson Jul 3, 2026
  6. github-project-automation
    moved this to Todo in Unittest & doctest issueson Jul 3, 2026
  7. pablogsal
    added a commit that references this issue on Sep 18, 2026

    gh-149640: Add new GitHub action to test lazy_imports=all against tes…

    b62e028
  8. StanFromIreland commented on Oct 1, 2026

    @StanFromIreland
    StanFromIreland
    on Oct 1, 2026
    Member
    More actions

    It's now tested in the CI, so I'm going to close this.

    Reacted by Hugo van Kemenade and Brittany Reynoso
  9. StanFromIreland
    closed this as completedon Oct 1, 2026
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

    3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixestestsTests in the Lib/test dirTests in the Lib/test dirtopic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Unittest & doctest issues
      Status
      Done
      Show more project fields

    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.