As Noam Postavsky mentioned, there was an unconditional (forward-line 1) expression. The issue manifests itself in a different way too. In the example that David Liu gave, add a decorator to the function on the first line. Then `python-shell-send-defun` enters an infinite loop. The attached patch fixes both these issues. `(forward-line 1)` should be called only when `(forward-line -1)` moves Point and `(looking-at..` returns false.