Skip to content

Properly lazily import shutil - #3023

Merged
Rowlando13 merged 5 commits into
pallets:stablefrom
ofek:patch-1
Aug 8, 2025
Merged

Properly lazily import shutil#3023
Rowlando13 merged 5 commits into
pallets:stablefrom
ofek:patch-1

Conversation

@ofek

@ofek ofek commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

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

ofek commented Jul 31, 2025

Copy link
Copy Markdown
Contributor Author

Okay, that's everything!

@davidism

Copy link
Copy Markdown
Member

Can you target this at stable instead?

@davidism

Copy link
Copy Markdown
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

ofek commented Jul 31, 2025

Copy link
Copy Markdown
Contributor Author

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

davidism commented Jul 31, 2025

Copy link
Copy Markdown
Member

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.

@Rowlando13

Rowlando13 commented Aug 7, 2025

Copy link
Copy Markdown
Member

@ofek Can you rebase onto current stable. There are my commits that merge stable into master on the branch. Same thing happened to me and I am not sure how exactly.

@ofek

ofek commented Aug 8, 2025

Copy link
Copy Markdown
Contributor Author

Done!

@Rowlando13
Rowlando13 merged commit 1f40020 into pallets:stable Aug 8, 2025
10 checks passed
@ofek
ofek deleted the patch-1 branch August 8, 2025 20:00
@kdeldycke kdeldycke added this to the 8.2.3 milestone Aug 12, 2025
@Rowlando13

Copy link
Copy Markdown
Member

@ofek Could you please add a change entry for this on another PR. I did not see there was not one.

@AndreasBackx

Copy link
Copy Markdown
Collaborator

I'll take care of the CHANGES mention, don't worry about it.

@Rowlando13 Rowlando13 modified the milestones: 8.2.3, 8.3.0 Aug 24, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 8, 2025
@kdeldycke kdeldycke added the parsing Parsing, parameters, commands, chaining, context label Aug 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

parsing Parsing, parameters, commands, chaining, context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants