Skip to content

Commit

Permalink
Avoid importing os unless necessary
Browse files Browse the repository at this point in the history
Normally I wouldn't push the line on PEP 8 for importing `os`, but
`win32.lib.pywin32_bootstrap` is imported by `site` at Python startup via
pywin32.pth. Programs that care a lot about startup time might appreciate our
caution here.
  • Loading branch information
wkschwartz committed Jan 20, 2021
1 parent 7a6de27 commit 74c96dc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion win32/Lib/pywin32_bootstrap.py
Expand Up @@ -6,14 +6,14 @@
# modules are imported.
# If Python has `os.add_dll_directory()`, we need to call it with this path.
# Otherwise, we add this path to PATH.
import os


try:
import pywin32_system32
except ImportError: # Python ≥3.6: replace ImportError with ModuleNotFoundError
pass
else:
import os
# We're guaranteed only that __path__: Iterable[str]
# https://docs.python.org/3/reference/import.html#__path__
for path in pywin32_system32.__path__:
Expand Down

0 comments on commit 74c96dc

Please sign in to comment.