This uses sys._getframe()[0], a private function which appears to be officially supported by CPython but is not guaranteed to exist in other interpreters. Needless to say, you probably shouldn't use this in any serious capacity, even if you're using CPython.
That said... I wonder what it would take to add support for labels. Jumping back to a previous location would be trivial; just create a sister function to associate the line with some unique string. But is there any way to register a label for a line that hasn't been executed?
I know CPython normally precompiles modules instead of literally interpreting them line-by-line, but I've never seen any code that interfaces with the precompiler itself. Does CPython support anything like preprocessor commands that might make it possible to support future labels?
You could easily wrap the interpreter with a custom preprocessor, but that's boring.
[0] https://docs.python.org/3/library/sys.html#sys._getframe
Python being python, can't you swap out the import machinery and change which compile function is called, alternatively call your own preprocessor before compiling?
I think goto has been implemented in a few different ways in python. Here's another example which abuses existing syntax and edits the bytecode of the function after its compiled: https://pypi.org/project/goto-statement/