Replace ``old`` with ``new`` in ``text``, asserting exactly one occurrence.
(text: str, old: str, new: str)
| 101 | |
| 102 | |
| 103 | def replace_once(text: str, old: str, new: str) -> str: |
| 104 | """Replace ``old`` with ``new`` in ``text``, asserting exactly one occurrence.""" |
| 105 | assert text.count(old) == 1, f"Expected exactly one occurrence of {old!r}" |
| 106 | return text.replace(old, new) |
| 107 | |
| 108 | |
| 109 | def run_bash_blocks( |
no outgoing calls