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 — Use lazy imports in argparse · Issue #154638 · python/cpython

Use lazy imports in argparse #154638

New issue
Copy link
New issue
Copy link
Closed
Closed
Use lazy imports in argparse#154638
Copy link
Assignees
savannahostrowski
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

Description

@savannahostrowski
savannahostrowski
opened on Jul 24, 2026
Issue body actions

argparse currently defers importing copy, difflib, shutil, textwrap, and warnings using inline imports, while importing re and gettext eagerly at module scope. I think these can safely be replaced with module-level explicit lazy imports, which will make the module’s dependencies more readable and reduce the cost of a bare import argparse.

On my machine, preliminary release-build measurements using -S -X importtime show the median cumulative import time for argparse decreasing by approximately 67%, from 4,792 µs to 1,595 µs across 15 alternating runs.

Linked PRs

  • GH-154638: Use lazy imports in argparse #154639

Activity

  1. savannahostrowski
    self-assigned this
    on Jul 24, 2026
  2. savannahostrowski
    added this to Argparse issueson Jul 24, 2026
  3. savannahostrowski
    added
    performancePerformance or resource usagePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on Jul 24, 2026
  4. savannahostrowski
    added a commit that references this issue on Jul 24, 2026

    GH-154638: Use lazy imports in argparse (#154639)

    f717b25
  5. savannahostrowski
    closed this as completedon Jul 24, 2026
  6. github-project-automation
    moved this to Doc issues in Argparse issueson Jul 24, 2026
  7. hugovk
    added a parent issue on Jul 30, 2026
    • Improve import time of various stdlib modules #154675
  8. mbeijen
    added a commit that references this issue on Aug 14, 2026

    pythonGH-154638: Use lazy imports in argparse (python#154639)

    265692c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @savannahostrowski
    savannahostrowski

Labels

3.16new features, bugs and security fixesnew features, bugs and security fixesperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

Projects

  • Argparse issues
    Status
    Doc issues
    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.