MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / inject_docstring_text

Function inject_docstring_text

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

Source from the content-addressed store, hash-verified

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

Callers 4

instrumentFunction · 0.90
makepropFunction · 0.90
_decorate_with_warningFunction · 0.85

Calls 5

_dedent_docstringFunction · 0.85
minClass · 0.85
appendMethod · 0.45
insertMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected