Looking it up quickly it seems that inspect.getsourcelines[0] is just about perfect. Combining that with a slight misuse of inspect.cleandoc[1] and you've basically got the OP reproduced without even needing to resort to anything especially tricky.
[0] https://docs.python.org/3/library/inspect.html#inspect.getso... [1] https://docs.python.org/3/library/inspect.html#inspect.clean...