From fa6caa6ca8489103d22d23f8f4ae4d3569bb115e Mon Sep 17 00:00:00 2001 From: "Yilei \"Dolee\" Yang" Date: Thu, 23 Jun 2022 12:41:05 -0700 Subject: [PATCH] Only call get_future_imports when needed (#3135) --- src/black/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index 4200066..2d04cf8 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -1172,10 +1172,10 @@ def format_str(src_contents: str, *, mode: Mode) -> str: def _format_str_once(src_contents: str, *, mode: Mode) -> str: src_node = lib2to3_parse(src_contents.lstrip(), mode.target_versions) dst_contents = [] - future_imports = get_future_imports(src_node) if mode.target_versions: versions = mode.target_versions else: + future_imports = get_future_imports(src_node) versions = detect_target_versions(src_node, future_imports=future_imports) normalize_fmt_off(src_node, preview=mode.preview) -- 2.39.5