Subject: 30.0.50; [PATCH] ; Check the process param in function (python-shell-completion-at-point)
From: Lin Sun <[email-masked]>
To: [email-masked]
Date: Wed, 1 May 2024 22:49:29 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

There is an unexpected error message happening with function
`python-shell-completion-at-point`.
> Wrong type argument: processp, nil
It happened because the function does NOT check the process param.
The patch will check the param and display a user error message gracefully.

Steps to reproduce the issue.
1. $ emacs -q /tmp/a.py # start emacs and open a python source file
2. type "C-c C-p" (or M-x run-python) to start a python shell
3. type exit() to stop the python process but the buffer still exists
4. M-x python-shell-completion-at-point  will get the error message

Please help review the patch. Thanks. Regards
From aa44c95c7f13f2d68be83260e618cf4d806b313b Mon Sep 17 00:00:00 2001
From: Lin Sun <[email-masked]>
Date: Wed, 1 May 2024 06:55:31 +0000
Subject: [PATCH] ; Check the process param in function
 (python-shell-completion-at-point)

* lisp/progmodes/python.el (python-shell-completion-at-point):
  Check the process param at the beginning of the function.
---
 lisp/progmodes/python.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index d6c29e5ffc..4b2e2f8215 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4708,6 +4708,8 @@ python-shell-completion-at-point
 Optional argument PROCESS forces completions to be retrieved
 using that one instead of current buffer's process."
   (setq process (or process (get-buffer-process (current-buffer))))
+  (unless process
+    (user-error "No active python inferior process"))
   (let* ((is-shell-buffer (derived-mode-p 'inferior-python-mode))
          (line-start (if is-shell-buffer
                          ;; Working on a shell buffer: use prompt end.
-- 
2.20.5