Skip to content

Properly lazily import shutil #3023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: stable
Choose a base branch
from
Open

Properly lazily import shutil #3023

wants to merge 9 commits into from

Conversation

ofek
Copy link
Contributor

@ofek ofek commented Jul 31, 2025

I agree with the intention to lazily import but it wasn't actually happening. Locally I get the following on Python 3.12:

❯ python -m timeit -n 1 -r 1 "import shutil"
1 loop, best of 1: 8.09 msec per loop

@ofek
Copy link
Contributor Author

ofek commented Jul 31, 2025

Okay, that's everything!

@davidism
Copy link
Member

Can you target this at stable instead?

@davidism
Copy link
Member

There's a test that checks what modules are imported, you can probably remove shutil from that list as well.

@ofek ofek changed the base branch from main to stable July 31, 2025 20:25
@ofek
Copy link
Contributor Author

ofek commented Jul 31, 2025

I changed to stable and updated that test! If it's fine with you, I'm interested in the coming weeks/months making sure that everything (within reason) is lazily imported.

@davidism
Copy link
Member

davidism commented Jul 31, 2025

Definitely, it's a bit annoying to code, but I think the speed is worth it for the CLI. We want to distinguish between what's going to be imported no matter what (general Python startup / used everywhere anyway) versus what only comes up in certain use cases. That's what that import test is for, so we know if something gets imported unintentionally, and can review imports from time to time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants