From 70456c227aad105addc573586672dd909f50c659 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 12 May 2026 11:40:39 -0500 Subject: refactor(prog-python): extract the mypy and pdb command builders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I pulled the command-string construction out of `cj/python-mypy` and `cj/python-debug` into `cj/--python-mypy-command` and `cj/--python-debug-command`. The wrappers stay thin — resolve the target, hand off to `compile` or `pdb`. With the command shape in a pure helper I can unit-test it directly instead of stubbing `compile` and `pdb`. --- modules/prog-python.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'modules/prog-python.el') diff --git a/modules/prog-python.el b/modules/prog-python.el index a26b9760..5720e25e 100644 --- a/modules/prog-python.el +++ b/modules/prog-python.el @@ -57,19 +57,26 @@ Install with: pip install mypy") (executable-find pyright-path)) (lsp-deferred))) +(defun cj/--python-mypy-command (target) + "Return the shell command that runs mypy against TARGET." + (format "%s %s" mypy-path (shell-quote-argument target))) + +(defun cj/--python-debug-command (file) + "Return the shell command that runs pdb against FILE." + (format "python3 -m pdb %s" (shell-quote-argument file))) + (defun cj/python-mypy () "Run mypy static type checker on the current Python file or directory." (interactive) (if (executable-find mypy-path) - (let ((target (or (buffer-file-name) default-directory))) - (compile (format "%s %s" mypy-path (shell-quote-argument target)))) + (compile (cj/--python-mypy-command (or (buffer-file-name) default-directory))) (message "mypy not found. Install with: pip install mypy"))) (defun cj/python-debug () "Start Python debugger (pdb) on the current file." (interactive) (if buffer-file-name - (pdb (format "python3 -m pdb %s" (shell-quote-argument buffer-file-name))) + (pdb (cj/--python-debug-command buffer-file-name)) (message "No file associated with this buffer"))) (defun cj/python-mode-keybindings () -- cgit v1.2.3