MCPcopy
hub / github.com/psf/black / format_code

Function format_code

src/blackd/__init__.py:218–243  ·  view source on GitHub ↗
(
    *,
    req_str: str,
    fast: bool,
    mode: black.FileMode,
    then: datetime,
    only_diff: bool,
    executor: Executor,
    executor_semaphore: asyncio.BoundedSemaphore,
)

Source from the content-addressed store, hash-verified

216
217
218async def format_code(
219 *,
220 req_str: str,
221 fast: bool,
222 mode: black.FileMode,
223 then: datetime,
224 only_diff: bool,
225 executor: Executor,
226 executor_semaphore: asyncio.BoundedSemaphore,
227) -> str:
228 async with executor_semaphore:
229 loop = asyncio.get_event_loop()
230 formatted_str = await loop.run_in_executor(
231 executor, partial(black.format_file_contents, req_str, fast=fast, mode=mode)
232 )
233
234 if not only_diff:
235 return formatted_str
236
237 now = datetime.now(timezone.utc)
238 src_name = f"In\t{then}"
239 dst_name = f"Out\t{now}"
240 return await loop.run_in_executor(
241 executor,
242 partial(black.diff, req_str, formatted_str, src_name, dst_name),
243 )
244
245
246def parse_mode(headers: MultiMapping[str]) -> black.Mode:

Callers 1

handleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected