Shouldn't it be not source_code.endswith(linesep) here? Otherwise it won't works with "\r\n"

    In [1]: "qsdqsd\r\n"[-1]
    Out[1]: '\n'