add blog posts: dollcode, python-goto

This commit is contained in:
2025-05-12 10:05:59 -07:00
parent e0e86e964c
commit 8a2343335c
14 changed files with 445 additions and 1 deletions

View File

@ -0,0 +1,27 @@
_goto = type('goto', (object,), dict(__and__=lambda _, other: (_goto(other.line))))
goto = _goto()
def _goto(lineno):
frame = sys._getframe().f_back.f_back
called_from = frame
def hook(frame, event, _):
if event == 'line' and frame == called_from:
try:
frame.f_lineno = lineno
except ValueError as e:
print("jump failed:", e)
while frame:
frame.f_trace = None
frame = frame.f_back
return None
return hook
# it doesn't think we actually need to set the hook for each frame
# while frame:
# frame.f_trace = hook
# frame = frame.f_back
called_from.f_trace = hook
sys.settrace(hook)