import re


def eliminate_newlines_after_function_definition_in_string(code: str) -> str:
    """Eliminates all newlines after the function definition in a string, e.g.

    def foo(a):

        return a + 1

    will become:

    def foo(a):
        return a+1"""

    return re.sub(
        pattern=r"(def \w+\([^:]*\):)(\s*)\n",
        repl=r"\1\n",
        string=code,
        flags=re.M | re.S,
    )