Skip to content
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

Decrease cost of ipynb code path when unneeded #3748

Merged
merged 6 commits into from Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -45,6 +45,8 @@

<!-- Changes that improve Black's performance. -->

- Avoid importing `IPython` in a case where we wouldn't need it (#3748)

### Output

<!-- Changes to Black's terminal output and error messages -->
Expand Down
7 changes: 6 additions & 1 deletion src/black/handle_ipynb_magics.py
Expand Up @@ -58,8 +58,13 @@ class Replacement:
@lru_cache()
def jupyter_dependencies_are_installed(*, verbose: bool, quiet: bool) -> bool:
try:
import IPython # noqa:F401
# isort: off
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
# tokenize_rt is less commonly installed than IPython
# and IPython is expensive to import
import tokenize_rt # noqa:F401
import IPython # noqa:F401

# isort: on
except ModuleNotFoundError:
if verbose or not quiet:
msg = (
Expand Down