jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 262 forks source link

Getting Lisp nesting exceeds ‘max-lisp-eval-depth' error while running elpy-shell-send-region-or-buffer #1976

Open kourosh2 opened 2 years ago

kourosh2 commented 2 years ago

Hi, First of all thank you for developing and maintaining elpy. I cannot emphasize how important elpy is in my workflow and how much I appreciate your efforts.

Today I updated my emacs to version 28.1-3 and after updating, I am not able to run elpy-shell-send-region-or-buffer (bound to C-c C-c key stroke). More specifically, I can run the code line-by-line but cannot run a region (or the whole buffer). It gives me Lisp nesting exceeds ‘max-lisp-eval-depth' error. python-shell-send-region however is working with no problem.

My configuration

Result of (elpy-config)

Elpy Configuration

Emacs.............: 28.1
Elpy..............: 1.35.0
Virtualenv........: main_env (/Users/kourosh/.virtualenvs/main_env)
Interactive Python: python3 3.9.12 (/Users/kourosh/.virtualenvs/main_env/bin/python3)
RPC virtualenv....: main_env (/Users/kourosh/.virtualenvs/main_env)
 Python...........: python3 3.9.12 (/Users/kourosh/.virtualenvs/main_env/bin/python3)
 Jedi.............: 0.18.1
 Autopep8.........: 1.6.0
 Yapf.............: 0.32.0
 Black............: 22.3.0
Syntax checker....: flake8 (/Users/kourosh/.virtualenvs/main_env/bin/flake8)

Warnings

Options

Elpy configuration in my init.el

;; Use elpy, https://github.com/jorgenschaefer/elpy/wiki

(require 'elpy)
;; Enables python mode
(elpy-enable)

(setq elpy-rpc-virtualenv-path "~/.virtualenvs/main_env")

(add-hook 'elpy-mode-hook
(lambda ()
(set (make-local-variable 'company-backends)
     '((company-dabbrev-code company-yasnippet elpy-company-backend)))))

;; Disable autocomplete mode in python mode
(add-hook 'python-mode-hook (lambda ()
                              (auto-complete-mode -1)))

;; Enable Flycheck instead of flymake
(when (require 'flycheck nil t)
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'flycheck-mode))

;; ;; For elpy
;; (setq elpy-rpc-python-command "python3")
;; ;; For interactive shell
;; (setq python-shell-interpreter "python3")

;; Uses ipython as shell. C-c C-z to switch to shell; C-c C-c to run current file
;;(elpy-use-ipython "ipython3")
;; (setq python-shell-interpreter "ipython3" python-shell-interpreter-args "--simple-prompt --pprint")

(add-hook 'python-mode-hook 'flyspell-prog-mode)

;; Open .psf, .jnl and .rpy files in Python mode (for abaqus)
(add-to-list 'auto-mode-alist '("\\.psf\\'" . python-mode))
(add-to-list 'auto-mode-alist '("\\.jnl\\'" . python-mode))
(add-to-list 'auto-mode-alist '("\\.rpy\\'" . python-mode))

(provide 'kk-python-mode)
jotsif commented 2 years ago

I have the same problem.

After some debugging I think the problem comes from this change https://github.com/emacs-mirror/emacs/commit/e27385ec372b36822958ebed6792ca806b1a0c3d Not sure how to fix it yet though

jotsif commented 2 years ago

Ok, the problem is that Elpy overwrites python-shell-send-file with its own version that calls python-shell-send-string. But in 28.1 python-shell-send-string can call python-shell-send-file so the program enters an infinite recursion that triggers the max-list-eval-depth.

Quick fix is adding (setq elpy-shell-echo-output nil) to init.el since this bypass overwriting python-shell-send-file

kourosh2 commented 2 years ago

Many thanks @jotsif. That fixes the issue for the time being.