MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / inject_docstring_text

Function inject_docstring_text

lib/sqlalchemy/util/langhelpers.py:2200–2217  ·  view source on GitHub ↗
(
    given_doctext: Optional[str], injecttext: str, pos: int
)

Source from the content-addressed store, hash-verified

2198
2199
2200def inject_docstring_text(
2201 given_doctext: Optional[str], injecttext: str, pos: int
2202) -> str:
2203 doctext: str = _dedent_docstring(given_doctext or "")
2204 lines = doctext.split("\n")
2205 if len(lines) == 1:
2206 lines.append("")
2207 injectlines = textwrap.dedent(injecttext).split("\n")
2208 if injectlines[0]:
2209 injectlines.insert(0, "")
2210
2211 blanks = [num for num, line in enumerate(lines) if not line.strip()]
2212 blanks.insert(0, 0)
2213
2214 inject_pos = blanks[min(pos, len(blanks) - 1)]
2215
2216 lines = lines[0:inject_pos] + injectlines + lines[inject_pos:]
2217 return "\n".join(lines)
2218
2219
2220_param_reg = re.compile(r"(\s+):param (.+?):")

Callers 4

instrumentFunction · 0.90
makepropFunction · 0.90
_decorate_with_warningFunction · 0.85

Calls 7

_dedent_docstringFunction · 0.85
minClass · 0.85
splitMethod · 0.80
stripMethod · 0.80
appendMethod · 0.45
insertMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected