Skip to content

MAINT: defer the import of shutil #18278

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

Merged
merged 1 commit into from
Feb 1, 2021
Merged

MAINT: defer the import of shutil #18278

merged 1 commit into from
Feb 1, 2021

Conversation

cgohlke
Copy link
Contributor

@cgohlke cgohlke commented Feb 1, 2021

numpy/lib/_datasource.py is going through the hoops deferring the import of lzma and bz2 until needed:

# Using a class instead of a module-level dictionary
# to reduce the initial 'import numpy' overhead by
# deferring the import of lzma, bz2 and gzip until needed

However the lzma and bz2 modules were already loaded during import shutil earlier:

https://github.com/python/cpython/blob/49926cf2bcc8b44d9b8f148d81979ada191dd9d5/Lib/shutil.py#L21-L33

Also deferring the import of shutil reduces the initial numpy import time by almost 5% on my system.

@charris charris merged commit f103c9e into numpy:master Feb 1, 2021
@charris
Copy link
Member

charris commented Feb 1, 2021

Thanks @cgohlke .

@charris charris changed the title ENH: defer the import of shutil MAINT: defer the import of shutil Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants