You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Defer mimetypes, locale, glob and runpy to their use sites
Four more single-use stdlib imports on the `import IPython` path:
- `mimetypes` (and the `winreg`/`_winapi` probing it does) in
`IPython.core.display`, used only to guess the type of an embedded video;
- `locale` in `IPython.utils.encoding`, consulted only when the stream
encoding is missing or ascii -- which it usually is not, so this was an
import for a call that mostly never happened;
- `glob` in `IPython.utils.path`, used only by `shellglob()`;
- `runpy` in `IPython.core.interactiveshell`, used only by
`safe_run_module()`.
Making `mimetypes` lazy surfaced that `tests/test_path.py` registers a stub
`winreg` module in `sys.modules` and never removes it, so any stdlib module
importing `winreg` later in the session -- `mimetypes` does, to decide
whether to read the Windows registry -- found the stub and tried to use it.
The only test that needs `winreg` runs on Windows only, so import it there
and leave `sys.modules` alone everywhere else.
The encoding tests reached `locale` through `IPython.utils.encoding.locale`;
patch the `locale` module itself, which is the same object either way.
0 commit comments