Title: Use lazy imports in argparse · Issue #154638 · python/cpython · GitHub
Open Graph Title: Use lazy imports in argparse · Issue #154638 · python/cpython
X Title: Use lazy imports in argparse · Issue #154638 · python/cpython
Description: 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,...
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/python/cpython/issues/154638
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use lazy imports in argparse","articleBody":"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.\n\nOn 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.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154639\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/savannahostrowski","@type":"Person","name":"savannahostrowski"},"datePublished":"2026-07-24T16:59:29Z","url":"https://github.com/python/cpython/issues/154638"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:47a87fce-0d7f-eaba-7c17-664677528bf7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC34:B53AF:355FDE6:470D73D:6B020383 |
| html-safe-nonce | cb0c1fdaa45901399b6f4694d7b6db89a287d3b801faa3c0b5fdc0efedbd3169 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzM0OkI1M0FGOjM1NUZERTY6NDcwRDczRDo2QjAyMDM4MyIsInZpc2l0b3JfaWQiOiIyNzY2MjMyNTk0MjYwNTU4NzIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 08eee63fda65a4a6a50e1667cea1803953df22a60e898aa4235f4d80954dc869 |
| hovercard-subject-tag | issue:4970468595 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/154638/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a56cb447572d61d5f31000a9421f067d4b9ff43c851501d70329e40196c30820/python/cpython/issues/154638 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a56cb447572d61d5f31000a9421f067d4b9ff43c851501d70329e40196c30820/python/cpython/issues/154638 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | savannahostrowski |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width