-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Possible lazy import opportunities in pathlib
#77621
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
Comments
Due to a python-ideas discussion about reducing boilerplate for __file__-relative path calculations, I was running "./python -X importtime -S -c 'import pathlib'" and noticed three potential candidates where it may be worthwhile deferring the imports until the modules are actually needed:
Using an optimised Python 3.7 on an SSD with warm disk caches, commenting out those 3 imports reduced my typical import times for pathlib from 12-13 ms to 7-8 ms) |
Also it's a smaller win, but it might be worth considering whether we can avoid the import of 'nt' on posix platforms and vice-versa. |
Did you mean the idea about module-level alias to dirname(file)? I think this is a dead horse. See bpo-33277. |
Personally I support moving imports of rarely used modules into functions that need them. But this is against PEP-8 and should be discussed more widely. Perhaps this rule should be weaken, we have to state what exceptions are permitted. |
I've moved the |
You could probably make this one lazy: Line 17 in 607b5e3
Users probably shouldn't pay the cost of importing The import-time speedup from making |
Three of four uses of |
SGTM! |
Import `contextlib`, `glob` and `re` only as required.
Import `contextlib`, `glob` and `re` only as required. Co-authored-by: Alex Waygood <[email protected]>
Resolving this issue as I believe there's nothing left to do!
|
Import `contextlib`, `glob` and `re` only as required. Co-authored-by: Alex Waygood <[email protected]>
Import `contextlib`, `glob` and `re` only as required. Co-authored-by: Alex Waygood <[email protected]>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: