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 — gh-137855: Improve import time of dataclasses by lazy importing `re` and `copy` modules by danielhollas · Pull Request #148379 · python/cpython

Conversation

@danielhollas

@danielhollas danielhollas commented Apr 11, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Split from #144387 as requested by @hugovk (tagging for review :-) This is a relatively minor win, the bigger win will come from lazy importing inspect in #144387

See below for tuna-visualized outputs from ./python -X importtime -c "import dataclasses"
(the absolute import numbers are not representative as I was running a debug python build)

Before

image

After

image
  • Issue: Improve import time of various stdlib modules #137855

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fidget-Spinner reacted with hooray emoji
All reactions
  • 🎉 1 reaction
danielhollas added 3 commits April 11, 2026 12:30
@danielhollas
Lazy import copy module
5206a52
@danielhollas
Lazy import re module
dca8fc3
@danielhollas
Add blurb
91473a5
@danielhollas
danielhollas requested a review from ericvsmith as a code owner April 11, 2026 12:23
@bedevere-app bedevere-app Bot added the awaiting review label Apr 11, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 11, 2026
Improve import time of various stdlib modules #137855
Closed
@danielhollas danielhollas mentioned this pull request Apr 11, 2026
gh-137855: Lazy import inspect module in dataclasses #144387
Merged
hugovk
hugovk reviewed Apr 11, 2026
View reviewed changes
Comment thread Lib/dataclasses.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/dataclasses.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/dataclasses.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

danielhollas and others added 4 commits April 11, 2026 17:19
@danielhollas @hugovk
Update Lib/dataclasses.py
8194309
Co-authored-by: Hugo van Kemenade <[email protected]>
@danielhollas
Reorder lazy imports
ab4bc95
@danielhollas
Hugo's regex-fu
933a9c5
@danielhollas
One more match
51fecc5
@danielhollas

danielhollas commented Apr 11, 2026

Copy link
Copy Markdown
Contributor Author

The failing Ubuntu build is a transient issue during dependency installation that will hopefully go away when the job is restarted.

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk
hugovk approved these changes Apr 11, 2026
View reviewed changes

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

danielhollas reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Apr 11, 2026
@hugovk
hugovk enabled auto-merge (squash) April 11, 2026 20:47
@hugovk
hugovk merged commit dd2735d into python:main Apr 11, 2026
97 of 99 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 11, 2026
@danielhollas
danielhollas deleted the dataclass-lazy-re branch April 11, 2026 21:12
@danielhollas danielhollas mentioned this pull request Apr 11, 2026
gh-148406: Fix annotations of _colorize.FancyCompleter #148408
Merged
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@danielhollas @hugovk @ljfp
pythongh-137855: Improve import time of dataclasses by lazy importing…
db4cffa
… `re` and `copy` modules (python#148379)

Co-authored-by: Hugo van Kemenade <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hugovk hugovk hugovk approved these changes
@ericvsmith ericvsmith Awaiting requested review from ericvsmith ericvsmith is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@danielhollas @hugovk
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.