MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / translate_docstrings

Function translate_docstrings

tools/synchro.py:364–406  ·  view source on GitHub ↗
(lines: list[str])

Source from the content-addressed store, hash-verified

362
363
364def translate_docstrings(lines: list[str]) -> list[str]:
365 for i in range(len(lines)):
366 for k in replacements:
367 if k in lines[i]:
368 # This sequence of replacements fixes the grammar issues caused by translating async -> sync
369 if "an Async" in lines[i]:
370 lines[i] = lines[i].replace("an Async", "a Async")
371 if "an 'Async" in lines[i]:
372 lines[i] = lines[i].replace("an 'Async", "a 'Async")
373 if "An Async" in lines[i]:
374 lines[i] = lines[i].replace("An Async", "A Async")
375 if "An 'Async" in lines[i]:
376 lines[i] = lines[i].replace("An 'Async", "A 'Async")
377 if "an asynchronous" in lines[i]:
378 lines[i] = lines[i].replace("an asynchronous", "a")
379 if "An asynchronous" in lines[i]:
380 lines[i] = lines[i].replace("An asynchronous", "A")
381 # This ensures docstring links are for `pymongo.X` instead of `pymongo.synchronous.X`
382 if "pymongo.asynchronous" in lines[i] and "import" not in lines[i]:
383 lines[i] = lines[i].replace("pymongo.asynchronous", "pymongo")
384 lines[i] = lines[i].replace(k, replacements[k])
385 if "Sync" in lines[i] and "Synchronous" not in lines[i] and replacements[k] in lines[i]:
386 lines[i] = lines[i].replace("Sync", "")
387 if "rsApplyStop" in lines[i]:
388 lines[i] = lines[i].replace("rsApplyStop", "rsSyncApplyStop")
389 if "async for" in lines[i] or "async with" in lines[i] or "async def" in lines[i]:
390 lines[i] = lines[i].replace("async ", "")
391 if "await " in lines[i] and "tailable" not in lines[i]:
392 lines[i] = lines[i].replace("await ", "")
393 for i in range(len(lines)):
394 for k in docstring_replacements: # type: ignore[assignment]
395 if f":param {k[1]}: **Not supported by {k[0]}**." in lines[i]:
396 lines[i] = lines[i].replace(
397 f"**Not supported by {k[0]}**.",
398 docstring_replacements[k], # type: ignore[index]
399 )
400
401 for line in docstring_removals:
402 if line in lines[i]:
403 lines[i] = "DOCSTRING_REMOVED"
404 lines[i + 1] = "DOCSTRING_REMOVED"
405
406 return [line for line in lines if line != "DOCSTRING_REMOVED"]
407
408
409def process_ignores(lines: list[str]) -> list[str]:

Callers 1

process_filesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected