Skip to content

Commit

Permalink
Only call get_future_imports when needed (#3135)
Browse files Browse the repository at this point in the history
  • Loading branch information
yilei committed Jun 23, 2022
1 parent 6463fb8 commit fa6caa6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/black/__init__.py
Expand Up @@ -1172,10 +1172,10 @@ def f(
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)
Expand Down

0 comments on commit fa6caa6

Please sign in to comment.