All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
c940f75)
This is a slight perf win for use-cases that don't invoke `reformat_many()`, but more importantly to me today it means I can use Black in pyscript.
import asyncio
from json.decoder import JSONDecodeError
import json
import asyncio
from json.decoder import JSONDecodeError
import json
-from concurrent.futures import Executor, ThreadPoolExecutor, ProcessPoolExecutor
from contextlib import contextmanager
from datetime import datetime
from enum import Enum
from contextlib import contextmanager
from datetime import datetime
from enum import Enum
import tokenize
import traceback
from typing import (
import tokenize
import traceback
from typing import (
from _black_version import version as __version__
from _black_version import version as __version__
+if TYPE_CHECKING:
+ from concurrent.futures import Executor
+
COMPILED = Path(__file__).suffix in (".pyd", ".so")
# types
COMPILED = Path(__file__).suffix in (".pyd", ".so")
# types
workers: Optional[int],
) -> None:
"""Reformat multiple files using a ProcessPoolExecutor."""
workers: Optional[int],
) -> None:
"""Reformat multiple files using a ProcessPoolExecutor."""
+ from concurrent.futures import Executor, ThreadPoolExecutor, ProcessPoolExecutor
+
executor: Executor
loop = asyncio.get_event_loop()
worker_count = workers if workers is not None else DEFAULT_WORKERS
executor: Executor
loop = asyncio.get_event_loop()
worker_count = workers if workers is not None else DEFAULT_WORKERS
mode: Mode,
report: "Report",
loop: asyncio.AbstractEventLoop,
mode: Mode,
report: "Report",
loop: asyncio.AbstractEventLoop,
) -> None:
"""Run formatting of `sources` in parallel using the provided `executor`.
) -> None:
"""Run formatting of `sources` in parallel using the provided `executor`.
self.assertEqual("".join(err_lines), "")
@event_loop()
self.assertEqual("".join(err_lines), "")
@event_loop()
- @patch("black.ProcessPoolExecutor", MagicMock(side_effect=OSError))
+ @patch("concurrent.futures.ProcessPoolExecutor", MagicMock(side_effect=OSError))
def test_works_in_mono_process_only_environment(self) -> None:
with cache_dir() as workspace:
for f in [
def test_works_in_mono_process_only_environment(self) -> None:
with cache_dir() as workspace:
for f in [
def test_cache_multiple_files(self) -> None:
mode = DEFAULT_MODE
with cache_dir() as workspace, patch(
def test_cache_multiple_files(self) -> None:
mode = DEFAULT_MODE
with cache_dir() as workspace, patch(
- "black.ProcessPoolExecutor", new=ThreadPoolExecutor
+ "concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor
):
one = (workspace / "one.py").resolve()
with one.open("w") as fobj:
):
one = (workspace / "one.py").resolve()
with one.open("w") as fobj:
def test_failed_formatting_does_not_get_cached(self) -> None:
mode = DEFAULT_MODE
with cache_dir() as workspace, patch(
def test_failed_formatting_does_not_get_cached(self) -> None:
mode = DEFAULT_MODE
with cache_dir() as workspace, patch(
- "black.ProcessPoolExecutor", new=ThreadPoolExecutor
+ "concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor
):
failing = (workspace / "failing.py").resolve()
with failing.open("w") as fobj:
):
failing = (workspace / "failing.py").resolve()
with failing.open("w") as fobj: